MR.*_*ABC 1 javascript c# ajax asp.net-mvc asp.net-mvc-4
是否有任何示例将多个对象发布到控制器.ajax帖子的数据必须如何?
[HttpPost]
public string Register(UserLogin userLogin, Contact contact)
{
}
Run Code Online (Sandbox Code Playgroud)
用户登录
public class UserLogin
{
public string Username { get; set; }
public string Password { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
联系
public class Contact
{
public string Firstname { get; set; }
public string Lastname { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
AJAX?
$.ajax({
type: "POST",
url: "SomeUrl"
dataType: "json",
contentType: "application/json; charset=utf-8",
data: ? });
Run Code Online (Sandbox Code Playgroud)
试试这个
$.ajax({
type: "POST",
url: "SomeUrl"
dataType: "json",
contentType: "application/json; charset=utf-8",
data: {
'userLogin' : {
'Username' : 'Username',
'Password' : 'Password'
},
'contact' : {
'Firstname' : 'Firstname',
'Lastname' : 'Lastname'
}
}
});
Run Code Online (Sandbox Code Playgroud)