Unable to bind data using Kendo ui grid
Natalaran Nagarazugari
This is my action method
public ActionResult Kendo([DataSourceRequest]DataSourceRequest request )
{
var emp = EmployeeManager.GetAllEmployees();
DataSourceResult result = emp.ToDataSourceResult(request);
return Json(result);
}
This is the grid code I got from the official website
@model IEnumerable<MyProject.Web.Models.EmployeeViewModels.EmployeeViewModel>
@using Kendo.Mvc.UI;
@(Html.Kendo().Grid<TalentPro.Employees.Employee>()
.Name("grid")
.DataSource(dataSource => dataSource //Configure the Grid data source.
.Ajax() //Specify that Ajax binding is used.
.Read(read => read.Action("Kendo", "Home")
) //Set the action method which will return the data in JSON format.
)
.Columns(columns =>
{
//Create a column bound to the ProductID property.
columns.Bound(product => product.Id);
//Create a column bound to the ProductName property.
columns.Bound(product => product.FirstName);
//Create a column bound to the UnitsInStock property.
columns.Bound(product => product.LastName);
columns.Bound(product => product.EmailId);
columns.Bound(product => product.PhoneNumber);
})
.Pageable() // Enable paging
.Sortable() // Enable sorting
)
I checked the official documentation and it helped me to integrate Kendo ui with my Asp.net core project . But I don't know where I am going wrong, it is not binding the data with the grid.
I've been trying multiple ways but to no avail. Can anyone help me with this problem.
Thanks in advance.
Natalaran Nagarazugari
Finally got the solution These are the changes I made
- Change ActionResult to JsonResult
- Added the following line to startup.cs:
".AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());"
thank you coby