Hi sowjanya,
Check this example. Now please take its reference and correct your code.
Refering the below articles i have created the example.
Database
Here I am making use of Microsoft’s Northwind Database. You can download it from here.
Download and install Northwind Database
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public JsonResult Get_AllCustomers()
{
NorthwindEntities entities = new NorthwindEntities();
List<Customer> Emp = entities.Customers.Take(10).ToList();
return Json(Emp, JsonRequestBehavior.AllowGet);
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', [])
app.controller('myCtrl', function ($scope, $http, $window) {
$scope.GetAllData = function () {
$http({
method: "POST",
url: "/Home/Get_AllCustomers",
dataType: 'json',
data: {},
headers: { "Content-Type": "application/json" }
}).then(function (response) {
$scope.employees = response.data;
}, function () {
$window.alert(response.Message);
});
}
});
</script>
<div ng-app="myApp">
<div ng-controller="myCtrl">
<input type="button" value="Generate Table" ng-click="GetAllData()" />
<p class="divHead">List of Employee</p>
<table cellpadding="12" class="table table-bordered table-hover">
<tr>
<td>
<b>ID</b>
</td>
<td>
<b>Name</b>
</td>
<td>
<b>Country</b>
</td>
<td>
<b>Actions</b>
</td>
</tr>
<tr ng-repeat="Emp in employees">
<td>
{{Emp.CustomerID}}
</td>
<td>
{{Emp.ContactName}}
</td>
<td>
{{Emp.Country}}
</td>
<td>
<input type="button" class="btn btn-warning" value="Update" ng-click="UpdateEmp(Emp)" />
<input type="button" class="btn btn-danger" value="Delete" ng-click="DeleteEmp(Emp)" />
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
Screenshot