In this example, we'll get app-data from the WebApi which runs a query with a parameter.
Click to see the result of a WebApi call with the shared code:
Result
@inherits Custom.Hybrid.Razor14
@{
var authorId = AsDynamic(App.Data["Persons"].First()).EntityId;
}
<button type="button" class="btn btn-primary" onclick="getAuthor(this, @authorId)">
Get Author #@authorId
</button>
<script>
function getAuthor(moduleContext, authorId) {
$2sxc(moduleContext).webApi.fetchJson('authorsquery/get?authorId=' + authorId)
.then(function (author) {
alert('Found author: '
+ author.FirstName + ' ' + author.LastName
+ ' (with ' + author.Books.length + ' books) \n\n'
+ 'The raw JSON: \n' + JSON.stringify(author)
);
});
}
</script>