I am using Asp.net core on the , in my controller I have the following code
[HttpPost]
public IActionResult GetUsers(string search)
{
var result = new List<UserDto>
{
new UserDto
{
UserId = 1,
FirstName = "jhon",
LastName = "doe",
UserName = "jhond",
Email = "jhond@AOL.com"
},
new UserDto
{
UserId = 2,
FirstName = "james",
LastName = "bond",
UserName = "jamesd",
Email = "jamesd@gmail.com"
}
};
var data = new DataSourceResult
{
Total = 2,
Data = result
};
return Json(data);
}
Now my DataSourceResult object looks like this
public class DataSourceResult<T>
{
/// <summary>
/// Extra data
/// </summary>
public object ExtraData { get; set; }
/// <summary>
/// Data
/// </summary>
public T Data { get; set; }
public bool Success => !Errors.Any();
/// <summary>
/// Errors
/// </summary>
public List<string> Errors { get; set; } = new List<string>();
public Exception Exception { get; set; }
/// <summary>
/// Total records
/// </summary>
public int Total { get; set; }
}
public class DataSourceResult : DataSourceResult<object>
{
}
My view has this code inside
<div id="gridUserInfo"></div>
$(document).ready(() => {
$("#gridUserInfo").kendoGrid({
dataSource: {
transport: {
read: {
url: "/User/GetUsers",
type: "POST",
dataType: "json",
data: function() {
var data = {
search: $('#search').val()
};
return data;
}
}
},
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "userId",
fields: {
firstName: { editable: false, type: "string" },
lastName: { editable: false, type: "string" },
userName: { editable: false, type: "string" },
email: { editable: false, type: "string" }
}
}
}
},
height: 550,
columns: [
{
field: "firstName",
title: "First Name"
},
{
field: "lastName",
title: "Last Name"
},
{
field: "userName",
title: "UserName"
},
{
field: "email",
title: "Email"
}
],
pageable: {
pageSizes: [10, 20, 30],
buttonCount: 5
}
});
}
After making a POST to my UserControllerI get the following json
{"extraData":null,"data":[{"userId":1,"firstName":"jhon","lastName":"doe","email":"jhond@AOL.com","userName":"jhond"},{"userId":2,"firstName":"james","lastName":"bond","email":"jamesd@gmail.com","userName":"jamesd"}],"success":true,"errors":[],"exception":null,"total":2}
But it is not displaying that information on the grid, What am I doing wrong?
