Hi SUJAYS,
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
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult GetCustomers()
{
NorthwindEntities entities = new NorthwindEntities();
var customers = entities.Customers.Select(x => new { Id = x.CustomerID, Name = x.ContactName, Country = x.Country }).ToList();
return Json(customers, JsonRequestBehavior.AllowGet);
}
}
View
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="https://code.angularjs.org/1.3.0/angular.js"></script>
<script type="text/javascript" src="https://rawgithub.com/vivendi/angular-datatables/master/src/angular-datatables.js"></script>
<script type="text/javascript" src="https://rawgithub.com/vivendi/angular-datatables/master/src/angular-datatables.directive.js"></script>
<script type="text/javascript" src="https://rawgithub.com/vivendi/angular-datatables/master/src/angular-datatables.factory.js"></script>
<script type="text/javascript" src="https://rawgithub.com/vivendi/angular-datatables/master/src/angular-datatables.bootstrap.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', ['datatables'])
app.controller('MyController', function ($scope, $http, $window) {
$http.get("/Home/GetCustomers").then(function (response) {
$scope.Customers = response.data;
}, function (response) {
alert(response.responseText);
});
});
</script>
<div ng-app="MyApp" ng-controller="MyController">
<div class="card-body">
<div class="table-responsive">
<h3 style="text-align: center;">
Customers List</h3>
<table id="tblCustomers" datatable="ng" class="table table-bordered">
<thead>
<tr>
<th>Customer Id</th>
<th>Name</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr dt-rows ng-repeat="m in Customers">
<td>{{m.Id}}</td>
<td>{{m.Name}}</td>
<td>{{m.Country}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Screenshot