场景:将对象传递给Controller可以正常工作,但传递不同类型(对象,字符串)的2个参数则不然。以下2个示例场景:
工作情景
JS:
function someEventFunction() {
var firstParam = {
'Name' : 'Kevin',
'Age' : 20
};
$.getJSON('Home/SomeURL', firstParam, function(response){
//some code
});
}
C#:
public JsonResult SomeURL(SomeModel pSomeModel)
{
return Json("Success", JsonRequestBehavior.AllowGet);
}
非工作情景
JS:
function someEventFunction() {
var firstParam = {
'Name' : 'Kevin',
'Age' : 20
};
var secondParam = 'some string';
$.getJSON('Home/SomeURL', {
pSomeModel: firstParam,
pSomeString: secondParam
}, function(response){
//some code
});
}
C#:
public JsonResult SomeURL(SomeModel pSomeModel, string pSomeString)
{
return Json("Success", JsonRequestBehavior.AllowGet);
}
似乎我在用对象传递其他东西时做错了什么。谁能告诉我什么是错的?