In my cshtml view, I have this kendo mvc grid control below.
@(Html.Kendo().Grid<MyModel>()
.Name("mygriddata")
.Columns(column =>
{
column.Bound(model => model.MyData).Title("No.").....
})
.Pageable(x => x.PageSizes(true).ButtonCount(3).Responsive(false))
.AutoBind(false)
.Filterable()
.Sortable(x => x.Enabled(true))
.Resizable(resizable => resizable.Columns(true))
.Scrollable(x => x.Height("auto"))
.PersistSelection()
.HtmlAttributes(new { style = "height: 50vh; margin-left:10px", @class = "form-group" })
.NoRecords()
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
.Model(model =>
{
model.Id(item => item.ID);
})
.Read(read => read.Action("MyActionMethod", "MyController"))
)
)
In in my controller, I have this async task action method.
public async Task<JsonResult> MyActionMethod([DataSourceRequest] DataSourceRequest request)
{
var data = await _service.GetData();
var model = data.Select((item, index) => new MyModel
{
MyData = ......
});
return new JsonResult { Data = model.ToDataSourceResultAsync(request), MaxJsonLength = int.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
Then, when accessing the view, I got this error. How to set up the Kendo mvc grid control in this case?
Message: The asynchronous action method 'MyActionMethod' returns a Task, which cannot be executed synchronously.