Hi rani,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
Model
public class CustomerModel
{
public string Customers { get; set; }
public string Total { get; set; }
}
Controller
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult GetCustomers(int page, int pageSize, int skip, int take)
{
NorthwindEntities entity = new NorthwindEntities();
var customers = entity.Customers.OrderBy(c => c.CustomerID).ToList();
CustomerModel model = new CustomerModel();
model.Total = customers.Count.ToString();
model.Customers = JsonConvert.SerializeObject(customers.Skip(skip).Take(take).ToList());
string json = JsonConvert.SerializeObject(model);
json = json.Replace(@"\", "");
json = json.Replace("\"[{", "[{");
json = json.Replace("}]\"", "}]");
return Content(json, "application/json");
}
}
View
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Index</title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2020.1.114/styles/kendo.default-v2.min.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="https://kendo.cdn.telerik.com/2020.1.114/js/angular.min.js"></script>
<script type="text/javascript" src="https://kendo.cdn.telerik.com/2020.1.114/js/kendo.all.min.js"></script>
<script type="text/javascript">
var app = angular.module("MyApp", ["kendo.directives"]);
app.controller("MyController", function ($scope, $http) {
$scope.mainGridOptions = {
dataSource: {
schema: { data: "Customers", total: "Total" },
serverPaging: true,
transport: {
read: function (e) {
var requestData = {
page: e.data.page,
pageSize: e.data.pageSize,
skip: e.data.skip,
take: e.data.take
};
$http({ method: 'POST', url: 'Home/GetCustomers', params: requestData })
.then(function (data) { e.success(data.data); });
}
},
pageSize: 10
},
pageSize: 10,
serverPaging: true,
serverSorting: true,
pageable: { refresh: true, pageSizes: [2, 25, 50] },
groupable: false,
sortable: true,
columns: [
{ field: "CustomerID", title: "Id" },
{ field: "ContactName", title: "Name" },
{ field: "City", title: "City" },
{ field: "Country", title: "Country" }
]
};
})
</script>
</head>
<body ng-app="MyApp" ng-controller="MyController">
<kendo-grid options="mainGridOptions"></kendo-grid>
</body>
</html>
Screenshot