我有一个使用ASP.NET MVC3,AJAX和JQUERY的问题。我有以下功能ASP MVC 3使用AJAX和JQUERY提交网址参数
[HttpPost]
public bool Update(int id, FormCollection collection)
这是我的jQuery来源:
$(document).ready(function() {
$('#btnUpdate').click(function (e) {
// Cancel default action
e.preventDefault();
var formCollection = $('#formId').serialize();
$.ajax({
cache: false,
type: 'POST',
url: '@Url.Action("Action","Controller")',
data: { id: $('#id').val(), collection: formCollection },
success: function (data) {
alert(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Error during process: \n' + xhr.responseText);
}
});
});
});
成功提交id参数,但集合(的FormCollection)包括带有{[0]数组:10000, [1]:收集}。我无法解决问题。当我重新设计这样的解决方案:
[HttpPost]
public bool Update(FormCollection collection)
$(document).ready(function() {
$('#btnUpdate').click(function (e) {
// Cancel default action
e.preventDefault();
$.ajax({
cache: false,
type: 'POST',
url: '@Url.Action("Action", "Controller")',
data: $('#formId').serialize(),
success: function (data) {
alert(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert('Error during process: \n' + xhr.responseText);
}
});
});
});
一切工作正常。我在传递2参数时做错了什么?
THX !!!
这种方式不能获得'FormCollection'你在这里传递模型类的集合定义。比如'public bool Update(int id,userProfile collection)' – Sender
请确定在IE中检查了这个[是否支持IE 8的JSON.stringify()?](http://stackoverflow.com/questions/3326893/is-json- stringify-supported-by-ie-8) – Sender