0

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); 
KeelRisk
  • 749
  • 1
  • 9
  • 27

1 Answers1

0

You should filter the grid data in another way. The usage of Html.BeginForm is the wrong way. Look at the answer and use either the filter toolbar or advanced searching. If you do decide to use you custom <input> field you should use postData with the property defined as function (see here) and use .trigger("reloadGrid", [{page: 1}]) to send the searching request to the controller. In the case you should add new parameter which corresponds the property name in the postData to the list of parameters of GridData.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798