I am trying to pass an id
and an object
which has four properties to an action controller but unfortunately it is not getting through and I get the following error.
The parameters dictionary contains a null entry for parameter 'batchID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult GetItems(Int32, Ebiquity.Reputation.Neptune.Web.Models.MyWorkFilterModel)' in 'Ebiquity.Reputation.Neptune.Web.Controllers.MyWorkController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
The JSON being passed is:
{
"batchID": 21610,
"filter":
{
"issueNo": "1",
"messageNo": "2",
"itemDate": "Wed, 05 Feb 2014 00:00:00 GMT",
"mediaName":"3"
}
};
The ajax call:
self.GetItems = function (batchID, issueNo, messageNo, itemDate, mediaName) {
var filter = {
issueNo: issueNo,
messageNo: messageNo,
itemDate: itemDate,
mediaName: mediaName
};
$.ajax({
type: "GET",
url: "/MyWork/GetItems",
data: JSON.stringify({
batchID: batchID,
filter: filter
}),
dataType: "json",
success: function (result) {
self.Items([]);
if (result.Items != null) {
var tempItems = ko.mapping.fromJS(result.Items, mappingOptions);
self.Items.push.apply(self.Items, tempItems());
}
}
});
};
The controller:
[HttpGet]
public JsonResult GetItems(int batchID, MyWorkFilterModel filter)
{
using (var rep = new WorkRepository(CurrentUser))
{
return Json(rep.GetBatch(batchID, filter), JsonRequestBehavior.AllowGet);
}
}
The filter model:
public class MyWorkFilterModel
{
public int? IssueNo { get; set; }
public int? MessageNo { get; set; }
public string MediaName { get; set; }
public DateTime? ItemDate { get; set; }
}