是否有将多个对象发布到 Controller 的示例。 ajax 帖子的数据必须是什么样子?
[HttpPost]
public string Register(UserLogin userLogin, Contact contact)
{
}
用户登录
public class UserLogin
{
public string Username { get; set; }
public string Password { get; set; }
}
联系方式
public class Contact
{
public string Firstname { get; set; }
public string Lastname { get; set; }
}
AJAX ?
$.ajax({
type: "POST",
url: "SomeUrl"
dataType: "json",
contentType: "application/json; charset=utf-8",
data: ? });
最佳答案
试试这个
$.ajax({
type: "POST",
url: "SomeUrl"
dataType: "json",
contentType: "application/json; charset=utf-8",
data: {
'userLogin' : {
'Username' : 'Username',
'Password' : 'Password'
},
'contact' : {
'Firstname' : 'Firstname',
'Lastname' : 'Lastname'
}
}
});
关于c# - MVC4 Controller 将多个 json 对象发布到 Controller ,ajax 发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17483109/