I have a Kendo Grid and would like to bind to the server-side WebAPI call result after the postback. The Grid result is based upon the selected dropdown value when the submit button is clicked. I am able to invoke the button click event, bind the webapi result to the Input.PermitList JSON result attribute. But the Grid is still empty. Anything I might have missed? Please suggest
Front-end code
<form method="post">
<h2>Permits</h2>
<div>
<label asp-for="Input.PermitCategoryList" class="control-label"></label>
<kendo-dropdownlist name="categories" for="@Model.Input.PermitCategory"
option-label="Select permit Category..."
class="form-control"
bind-to="@(new SelectList(@Model.Input.PermitCategoryList,"Alias","Name"))"></kendo-dropdownlist>
<span asp-validation-for="Input.PermitCategoryList" class="text-danger"></span>
</div>
<div>
<button name="btnGetPermit" icon="filter" type="submit" asp-page-handler="PermitList" class="k-button">Get Permits</button>
</div>
<div>
<h4>Permits</h4>
<kendo-grid name="grid" height="550" datasource-id="dataSource">
<groupable enabled="true" />
<sortable enabled="true" />
<pageable button-count="5" refresh="true" page-sizes="new int[] { 5, 10, 20 }">
</pageable>
<filterable enabled="true" />
<columns>
<column field="Id" title="Permit Id" />
<column field="Class" title="Permit Class" />
<column field="Name" title="Permit Name" />
<column field="Type" title="Permit Type" />
<column field="Fee" title="Permit Fee" />
</columns>
</kendo-grid>
</div>
<script>
var data = @LITSPermitting.Admin.Extensions.JavaScriptConverter.SerializeObject(Model.Input.PermitList);
var dataSource = new kendo.data.DataSource({
data: data,
pageSize:5
})
</script>
</form>
Back-end Button click event
[BindProperty]
public InputModel Input { get; set; }
public class InputModel
{
[Required]
[Display(Name = "Permit Category")]
public List<PermitCategoryDto> PermitCategoryList { get; set; }
public string PermitCategory { get; set; }
public JsonResult PermitList { get; set; }
}
/// <summary>
/// Get a list of Permits based upon the category request
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public async Task<ActionResult> OnPostPermitListAsync([DataSourceRequest]DataSourceRequest request)
{
await HttpContext.Session.LoadAsync();
Input.PermitCategoryList = HttpContext.Session.Get<List<PermitCategoryDto>>(Constants.PERMIT_CATEGORY_LIST);
//tp is the temporary permit type
string requestUri = Constants.PERMIT_CATEGORY_REQUEST_URI + Input.PermitCategory;
_response = await _client.GetAsync(requestUri);
if (_response.IsSuccessStatusCode)
{
//Storing the response details recieved from web api
var result = _response.Content.ReadAsStringAsync().Result;
//Deserializing the response recieved from web api and storing into the Permit list
var drResult = JsonConvert.DeserializeObject<List<PermitDto>>(result);
Input.PermitList=new JsonResult(drResult.ToDataSourceResult(request));
return Input.PermitList;
}
else
{
return NotFound();
}
}