Not able to bind data with Kendo ui grid

Here is my Action Method

 public ActionResult Kendo([DataSourceRequest]DataSourceRequest request )
    {
        var emp = EmployeeManager.GetAllEmployees();

        DataSourceResult result = emp.ToDataSourceResult(request);
        return Json(result);
    }


This is my grid code which i have taken from 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 have gone through official documentation it helped me to integrate Kendo ui with my Asp.net core Project. But i have no clue where i went wrong, its not binding the data with the grid.

I have been trying multiple ways but no use. Can anyone help me out to solve this issue.
Thanks in Advance.


Finally Got solution These are the changes i made

  • changed ActionResult to JsonResult
  • One more below line added in startup.cs
    ".AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());"
    Thanks for coby

  • In your controller method, replace

    return Json(result);
    

    with

    return Json(result, JsonRequestBehavior.AllowGet);
    

    MVC defaults to DenyGet for security reasons, so you have to manually set it to AllowGet, or it won't return correctly.

    It's important to note that this can expose a small vulnerability to your JSON object being returned if the browser being used is an older version (It has been fixed as of ). This should only be a concern if you're passing particularly sensitive information AND your users are able to access the page from outdated browsers.

    You can read more on the subject HERE and HERE.

    链接地址: http://www.djcxy.com/p/47784.html

    上一篇: 我如何修改Object构造函数

    下一篇: 无法使用Kendo ui网格绑定数据