admin管理员组文章数量:1023782
is there any example to post multiple objects to a controller. How the data for the ajax post have to look like ?
[HttpPost]
public string Register(UserLogin userLogin, Contact contact)
{
}
UserLogin
public class UserLogin
{
public string Username { get; set; }
public string Password { get; set; }
}
Contact
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: ? });
is there any example to post multiple objects to a controller. How the data for the ajax post have to look like ?
[HttpPost]
public string Register(UserLogin userLogin, Contact contact)
{
}
UserLogin
public class UserLogin
{
public string Username { get; set; }
public string Password { get; set; }
}
Contact
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: ? });
Share
Improve this question
asked Jul 5, 2013 at 7:12
MR.ABCMR.ABC
4,86213 gold badges47 silver badges89 bronze badges
3 Answers
Reset to default 5Try this
$.ajax({
type: "POST",
url: "SomeUrl"
dataType: "json",
contentType: "application/json; charset=utf-8",
data: {
'userLogin' : {
'Username' : 'Username',
'Password' : 'Password'
},
'contact' : {
'Firstname' : 'Firstname',
'Lastname' : 'Lastname'
}
}
});
Just need to change javascript
. Pass your object like this after creating
var loginObject = {
Username: uname,//get it using jQuery $('#Username').val()
Password : pswrd //same way
};
var contact = {
Firstname = "",
Lastname = "",
};
And in ajax call,
data: {userLogin: loginObject, contact: contactObject}
You can follow the below snippet
var userLogin = {
UserName : "", Password : ""
};
var contact = {
FirstName : "", LastName : ""
};
Then you can assin the data to the ajax call like data : {userLogin : userLogin, contact : contact}
is there any example to post multiple objects to a controller. How the data for the ajax post have to look like ?
[HttpPost]
public string Register(UserLogin userLogin, Contact contact)
{
}
UserLogin
public class UserLogin
{
public string Username { get; set; }
public string Password { get; set; }
}
Contact
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: ? });
is there any example to post multiple objects to a controller. How the data for the ajax post have to look like ?
[HttpPost]
public string Register(UserLogin userLogin, Contact contact)
{
}
UserLogin
public class UserLogin
{
public string Username { get; set; }
public string Password { get; set; }
}
Contact
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: ? });
Share
Improve this question
asked Jul 5, 2013 at 7:12
MR.ABCMR.ABC
4,86213 gold badges47 silver badges89 bronze badges
3 Answers
Reset to default 5Try this
$.ajax({
type: "POST",
url: "SomeUrl"
dataType: "json",
contentType: "application/json; charset=utf-8",
data: {
'userLogin' : {
'Username' : 'Username',
'Password' : 'Password'
},
'contact' : {
'Firstname' : 'Firstname',
'Lastname' : 'Lastname'
}
}
});
Just need to change javascript
. Pass your object like this after creating
var loginObject = {
Username: uname,//get it using jQuery $('#Username').val()
Password : pswrd //same way
};
var contact = {
Firstname = "",
Lastname = "",
};
And in ajax call,
data: {userLogin: loginObject, contact: contactObject}
You can follow the below snippet
var userLogin = {
UserName : "", Password : ""
};
var contact = {
FirstName : "", LastName : ""
};
Then you can assin the data to the ajax call like data : {userLogin : userLogin, contact : contact}
本文标签: cMVC4 controller post multiple json objects to controllerajax postStack Overflow
版权声明:本文标题:c# - MVC4 controller post multiple json objects to controller, ajax post - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745521291a2154326.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论