How to pass an object with a specific amount of data from the View to the Controller using ASP.net MVC and AngularJS
VIEW
var Person = {};
Person.IdPerson = 69425;
Person.Year = new Date().getFullYear();
$http.post('/API/Update_Person', { params: { Person: Person } }).then(function (response) {
});
CONTROLLER
public JsonResult Update_Person(ModelPerson Person)
{
var person = (from c in db.Person where c.IdPerson == Person.IdPerson && c.Year == Person.Year select c).FirstOrDefault();
return new JsonResult { Data = "OK", JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
Is there a better approach than this?
$http({
method: "post",
url: "/API/Person",
datatype: "json",
data: JSON.stringify(Person)
}).then(function (response) {
});