Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another alternative that allows you to stick within the knockout/upshot framework is to alter the upshot provide parameters operation name to include the paramaters as part of the route and/or querystring.</p> <p>The following example uses an 'ApplicationId' collected from the HTML as the parameter to a WebAPI call to a method that accepts an 'id' parameter as part of the route ('/api/controller/action/id'):</p> <p>Controller Method:</p> <pre><code>public class ClientDetailsScreenController : DataController { public ClientModel GetClient(int id) { var client = //Fetch client with id using your prefered method return client; } } </code></pre> <p>View HTML Upshot Context:</p> <pre><code>@(Html.UpshotContext(true).DataSource&lt;ClientDetailsScreenController&gt;(ctr =&gt; ctr.GetClient(0)))) </code></pre> <p>Note that the '0' passed to the GetClient method gets ignored by the DataSource method so can be anything that will make the method signature valid.</p> <p>Knockout View Model:</p> <pre><code>function ClientDetailsViewModel() { var self = this; //Store the operation name with a leading '/' for use later self.operationNameTemplate = upshot.dataSources.Client._providerParameters.operationName + "/"; //Observable property for the ApplicationId enter via HTML self.selectedApplicationId = ko.observable("1"); //Refresh Data Source Operation - Called in HTML when the ApplicaitonId changes self.refresh = function () { //Set the upshot operation name to include the id parameter value. upshot.dataSources.Client._providerParameters.operationName = self.operationNameTemplate + self.selectedApplicationId(); //Refresh the data source causing the bound HTMl to be updated. self.dataSource = upshot.dataSources.Client.refresh(); }; //Data Source Setup self.refresh(); self.clients = self.dataSource.getEntities(); } </code></pre> <p>Hope this helps anyone else who has been trying to get parameters passed to the server via upshot. If anyone has a better way then please let us know.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload