Reputation: 2506
I have a controller which has an action like this:
[HttpPost]
public ActionResult Assign(int reportId, List<int> clientIds)
{
// stuff
return View();
}
When I call it from the view from a table like this:
@using (Html.BeginForm("Assign", "Report", FormMethod.Post, new { reportId = 1} ))
{
...
<input type="checkbox" name="clientIds" value="@item.Id" checked>
I'm getting an error saying
The parameters dictionary contains a null entry for parameter 'reportId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Assign(Int32, System.Collections.Generic.List`1[System.Int32])'
As far as I can see the controller should be getting the value 1 for reportId - can anyone see where I'm going wrong?
I realise I could (should) be using a view model to get data from the client to the action but I need to do it this way for now...
Upvotes: 0
Views: 240
Reputation:
You using the wrong overload of BeginForm()
and adding reportId
as a html attribute, not a route value. You need to use this overload where the 3rd parameter is object routeValues
@using (Html.BeginForm("Assign", "Report", new { reportId = 1 }, FormMethod.Post))
Upvotes: 1