MVC4控制器将多个json对象发布到控制器,ajax发布 [英] MVC4 controller post multiple json objects to controller, ajax post

查看:100
本文介绍了MVC4控制器将多个json对象发布到控制器,ajax发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有将多个对象发布到控制器的示例. Ajax发布的数据看起来如何?

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; }
}

联系方式

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'
       }
   }
});

这篇关于MVC4控制器将多个json对象发布到控制器,ajax发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆