在我的網站,我收集的數字(排序)的列表,並與下面的代碼發送到我的MVC行動:爲什麼我的MVC Action沒有模型綁定我的集合?
$('#saveButton').click(function() {
var configId = $('#ConfigId').val();
var steps = new Array();
$('#stepList li').each(function (index) {
steps[index] = $(this).attr('stepId');
});
// Send the steps via ajax
$.ajax({
url: '" + Url.Action(MVC.GrmDeployment.EditStep.Reorder()) + @"',
type: 'POST',
dataType: 'json',
data: { configId: configId, stepIds: steps },
success: function (data) {
if (data.success) {
alert('Reorder was successful');
}
else {
alert(data.msg);
}
}
});
});
通過鍍鉻我看到這個發送以下數據通過有線:
configId:1
stepIds%5B%5D:3
stepIds%5B%5D:2
在我的控制,我有以下方法來接收值
public virtual ActionResult Reorder(int configId, ICollection<int> stepIds) { }
的問題是stepIds
集合爲空。任何人看到任何理由爲什麼
我見過各種資源說可以綁定到'IList <>'或'ICollection <>',事實證明我不得不使用特定的jquery選項來使它工作。 – KallDrexx