C# 将angularjs数组传递给ASP.NETMVC方法
所以,我有一个angularJS数组,我想将它传递给ASP.NETMVC方法,然后将其数据存储在数据库中 该数组如下所示:C# 将angularjs数组传递给ASP.NETMVC方法,c#,arrays,angularjs,asp.net-mvc,C#,Arrays,Angularjs,Asp.net Mvc,所以,我有一个angularJS数组,我想将它传递给ASP.NETMVC方法,然后将其数据存储在数据库中 该数组如下所示: telephone=[{'id':'T1','contactN':'212-289-3824'},{'id':'T2','contactN':'212-465-1290'}] 当我单击按钮时,它会触发以下JS函数: $scope.updateUserContacts = function () { $http.post('/Home/UpdateUserContac
telephone=[{'id':'T1','contactN':'212-289-3824'},{'id':'T2','contactN':'212-465-1290'}]代码>
当我单击按钮时,它会触发以下JS函数:
$scope.updateUserContacts = function () {
$http.post('/Home/UpdateUserContacts', { contactsData: $scope.telephone })
.then(function (response) {
$scope.users = response.data;
})
.catch(function (e) {
console.log("error", e);
throw e;
})
.finally(function () {
console.log("This finally block");
});
}
我的问题是,如何在ASP.NETMVC中接收此阵列?与此阵列兼容的格式是什么
下面是ASP.Net MVC方法的一个示例,但我不知道是什么类型和/或如何接收传递的数组
[HttpPost] //it means this method will only be activated in the post event
public JsonResult UpdateUserContacts(??? the received array)
{
......
}
类型应为列表
或数组
[HttpPost] //it means this method will only be activated in the post event
public JsonResult UpdateUserContacts(List<MyObj> contactsData)
{
......
}
你应该有这样的模型课
public class MyObj
{
public string id {get;set;}
public string contactN {get;set;}
}
类型应为列表
或数组
[HttpPost] //it means this method will only be activated in the post event
public JsonResult UpdateUserContacts(List<MyObj> contactsData)
{
......
}
你应该有这样的模型课
public class MyObj
{
public string id {get;set;}
public string contactN {get;set;}
}
在MVC应用程序中,您应该有电话课程
class Telephone
{
public string id;
public string contactN;
}
[HttpPost] //it means this method will only be activated in the post event
public JsonResult UpdateUserContacts(Telephone[] contactsData)
{
//Do something...
}
在MVC应用程序中,您应该有电话课程
class Telephone
{
public string id;
public string contactN;
}
[HttpPost] //it means this method will only be activated in the post event
public JsonResult UpdateUserContacts(Telephone[] contactsData)
{
//Do something...
}