Ajax:无法绑定多个参数

时间:2015-03-26 10:47:25

标签: ajax

嘿我试图在ajax post请求中绑定多个参数但是我收到以下错误 Can't bind multiple parameters to the request's content.
这是我的代码
MVC Api Controller Side

public void Post(Email email, PInformation pInformation)
        {
//do something.
        }  

Ajax Call

var mail = { mail: 'myemail', Password: 'pass' };
var ppInformation = { FirstName: 'James', LastName: 'Jones' };
var datum = { email: mail, pInformation: ppInformation };
$.ajax({

url: 'url',
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: "json",
data: JSON.stringify(datum),
success: function (result) {
    }
});

1 个答案:

答案 0 :(得分:1)

您需要使用复合材料,所以:

$.ajax({
   ...
   data: {form: datum},
});

您的控制器方法:

public String controlerMethod(@RequestBody FormData form){
 ...
}

您的表单模型:

class FormData {
    Email email;
    PInformation pInformation;

    // getters & setters
}

这个解决方案应该可行,但我不能说POST方法有多种RequestBody可供使用。