0
我的動作接受整數值的數組:如何使用Ajax獲取整數值數組到一個Action?
public ActionResult ActionName(int firstParamId, int secondParamId, int[] contactIds)
我使用下面的代碼但整數選定陣列不發送過來。
function btnSend_onclick() {
var firstParamId = 1;
var secondParamId= 2;
var selectedContactIds = [];
$('#ContactsListContainer input:checked').each(function() {
selectedContactIds.push($(this).val());
});
var params = {
firstParamId : firstParamId ,
secondParamId: secondParamId,
contactIds: selectedContactIds
};
$.get('/ControllerName/ActionName', JSON.stringify(params))
.done(function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
})
.fail(function(data) {
debugger;
alert(data.responseText);
});
}
我收到下面的錯誤每個參數:
The parameters dictionary contains a null entry for parameter 'firstParamId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Actionname(Int32, Int32, Int32[])'
in 'AppNamespace.MvcUI.Controllers.ControllerName'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.<br>Parameter name: parameters
出了什麼問題上面的代碼?
? – 2013-02-28 11:24:54
如果你有解決方法,請將它標記爲答案:) – PSR 2013-02-28 11:26:24
它沒有爲我工作。 – 2013-02-28 11:37:50