I am using the Kendo UI for ASP.NET Core MVC suite with a Razor Pages web application so I am trying to use the handler technique for the grid's server operations.
@(Html.Kendo().Grid<CustomerViewModel>()
.Name("CustomersGrid")
.Columns(columns =>
{
columns.Bound(x => x.CustomerId).Title("Student ID");
columns.Bound(x => x.CustomerName).Title("Name");
})
.Pageable()
.Sortable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(true)
.Read(read => read.Url("/Customers?handler=Read")))
)
I looked in the network tab and it is making the correct POST to http://localhost:5000/Customers?handler=Read however I am not ending up at my breakpoint and I get a status code 400.
In the razor page's code behind the Action method is named OnPostReadAsync
Any idea why this is not working? In addition to .Url also tried using read.Action and read.Route in the .Read property of the DataSource.
Here is the class with the action method:
public class IndexModel : PageModel
{
private readonly ICustomerRepository _customerRepository;
private readonly IMapper _mapper;
public IndexModel(ICustomerRepository customerRepository, IMapper mapper)
{
_customerRepository = customerRepository;
_mapper = mapper;
}
public IList<CustomerViewModel> Customers { get; set; }
public async Task<IActionResult> OnPostReadAsync([DataSourceRequest] DataSourceRequest request)
{
// THIS IS WHERE I WANT IT TO GO FOR READ
var customersFromDb = await _customerRepository.FilterAsync();
return new JsonResult(_mapper.Map<IList<Customer>, IList<CustomerViewModel>>(customersFromDb).ToDataSourceResult(request));
}
}