Hi mahesh213,
Check this example. Now please take its reference and correct your code.
Database
I have made use of the following table Customers with the schema as follows.

I have already inserted few records in the table.

You can download the database table SQL by clicking the download link below.
Download SQL file
Controller
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult Add(string name, string country)
{
TestEntities entities = new TestEntities();
entities.AddToCustomers(new Customer { Name = name, Country = country });
int id = 0;
if (entities.SaveChanges() > 0)
{
id = GetLastId() + 1;
return Json(id, JsonRequestBehavior.AllowGet);
}
else
{
id = GetLastId() + 1;
return Json(id, JsonRequestBehavior.AllowGet);
}
}
public JsonResult GetId()
{
int id = GetLastId() + 1;
return Json(id, JsonRequestBehavior.AllowGet);
}
private int GetLastId()
{
TestEntities entities = new TestEntities();
return entities.Customers.OrderByDescending(x => x.CustomerId).Select(x => x.CustomerId).FirstOrDefault();
}
}
View
<html>
<head>
<title>Index</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.8/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module("myApp", []);
app.controller("myCntrl", ['$scope', '$http', function ($scope, $http) {
$http.get("/Home/GetId/")
.then(function (response) {
$scope.Id = response.data;
}).then(function (response) {
$scope.Message = response.responseText;
});
$scope.Add = function () {
$http.get("/Home/Add/", { params: { name: $scope.Name, country: $scope.Country} })
.then(function (response) {
$scope.Id = response.data;
$scope.Name = "";
$scope.Country = "";
}).then(function (response) {
$scope.Message = response.responseText;
});
}
} ]);
</script>
</head>
<body ng-app="myApp" ng-controller="myCntrl">
<div>
Id:<input type="text" class="form-control" ng-model="Id" readonly="readonly" /><br />
Name:<input type="text" class="form-control" ng-model="Name" /><br />
Country:<input type="text" class="form-control" ng-model="Country" /><br />
<input type="button" value="Save" ng-click="Add()" />
</div>
</body>
</html>
Screenshot
