Monday, 26 August 2013

JSON data to KENDO UI Grid ASP.NET MVC 4

JSON data to KENDO UI Grid ASP.NET MVC 4

I have bit trouble getting data to show on my Kendo.Grid.
JSON is valid and it shows when clicking the link as text, but loading the
data n the Grid.
Here is the source, any help would be appreciated!
br. Eero
Controller
public ActionResult Index([DataSourceRequest]DataSourceRequest request)
{
using (var db = new CimDataContext())
{
IQueryable<Customer> customers = db.Customers;
DataSourceResult result = customers.ToDataSourceResult(request);
return Json(result, "text/x-json", JsonRequestBehavior.AllowGet);
}
}
Index.cshtml
@(Html.Kendo().Grid<KendoUIMvcCim.Models.Customer>()
.Name("grid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Index", "Customer"))
)
.Columns(columns =>
{
columns.Bound(customer => customer.Id);
columns.Bound(customer => customer.Name);
columns.Bound(customer => customer.Number);
columns.Bound(customer => customer.AgentID);
columns.Bound(customer => customer.Info);
columns.Bound(customer => customer.Email);
columns.Bound(customer => customer.StartTime);
columns.Bound(customer => customer.EndTime);
columns.Bound(customer => customer.Category);
})
.Pageable()
.Sortable()
)
Result on browser
{"Data":[{"Id":2,"Name":"Name1","Number":"040000000","AgentID":"1","Info":"info1","Email":"email1","StartTime":"\/Date(1360101600000)\/","EndTime":null,"Category":"Laser"},{"Id":3,"Name":"Name2","Number":"0400000000","AgentID":"2","Info":"info2","Email":"email2","StartTime":"\/Date(1360188000000)\/","EndTime":null,"Category":"Kaihi"}],"Total":2,"AggregateResults":null,"Errors":null}

No comments:

Post a Comment