ISSUE
I am trying to submit an asp.net mvc form and I get the following error. When the page initially loads it hits the GridData method successfully. If I click the Submit button in the view below, I get the following error.
ERROR
The parameters dictionary contains a null entry for parameter 'page' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult GridData(System.String, System.String, Int32, Int32)' in 'HunterEdge.Web.Controllers.DataController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
PARTIAL VIEW: This is the view data I'm trying to submit
@model HunterEdge.Web.Models.HarvestDataFilter
@using (Html.BeginForm("GridData", "Data"))
{
<div style=" width:300px; height:550px; float:left">
html removed for brevity
<input type="submit" value="Search" style=" margin-left:110px" />
</div>
}
CONTROLER ACTION METHOD I'M TRYING TO GET FORM DATA TO
public JsonResult GridData(string sidx, string sord, int page, int rows, HarvestDataFilter filter)
{
var results = (from a in db.t_harvest_statistics_elk
where a.year == "2008" && a.unit_number == 1
orderby a.id
select new { a.id, a.year, a.unit_number, a.total_hunters, a.bulls, a.cows }).ToList();
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = results.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var pageResults = results.Skip(pageIndex * pageSize).Take(pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from pageResult in pageResults
select new
{
id = pageResult.id,
cell = new[] {
pageResult.year.ToString(),
"Add",
pageResult.unit_number.ToString(),
pageResult.total_hunters.ToString(),
pageResult.bulls.ToString(),
"add",
pageResult.cows.ToString(),
"add",
"add",
"add"
}
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);