我正在尝试将数组变量从ajax传递给控制器, 但我没有得到控制器中的值
下面是我的代码
AJAX
function userDetailsClass() {
var userDetails = {};
userDetails.age = 12;
userDetails.Name = "Vignesh";
userDetails.lastName = "s";
debugger;
$.ajax({
url: "Home/userDetails",
data: JSON.stringify({
UserDetailsParam: userDetails
}),
responseType: "json",
success: successfn,
error: errorfn
});
function successfn(result) {
};
function errorfn(result) {
};
}
控制器
public ActionResult userDetails( string UserDetailsParam){
return View();
}
我也试过
public ActionResult userDetails( string[] UserDetailsParam){
return View();
}
答案 0 :(得分:1)
您的代码应该是这样的
$.ajax({
url: "Home/userDetails",
data: {
"UserDetailsParam":JSON.stringify(userDetails)//change this
},
responseType: "json",
success: successfn,
error: errorfn
});
答案 1 :(得分:0)
试试这个
var userDetails = {"age":'12',"Name":'Vignesh',"lastName":'s'};