I am using the following code in a view and I am trying to add the withdraw link at the end using an additional parameter but I get the following error:
System.ArgumentException: The parameters dictionary contains a null entry for parameter ‘personID’ of non-nullable type ‘System.Int32’ for method ‘System.Web.Mvc.ActionResult Withdraw(Int32, Int32)’ in ‘MaxMe2.Controllers.TeamController’. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
<% if(Model.departmentsDisplayCheck) {%>
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Status</th>
</tr>
<% foreach (var dep in Model.departmentsList){ %>
<tr>
<td><%: Html.ActionLink(dep.Name, "Details", "Department", new { id=dep.DepartmentID}, null) %></td>
<td><%: dep.DepartmentType.Type %></td>
<td><%: dep.DepartmentStatus.Status %></td>
<td><%: Html.ActionLink("Withdraw", "Withdraw", "Team", new { id = Model.personalInfo.PersonID, dep = dep.DepartmentID}, null)%></td>
</tr>
<% } %>
The controller method that I am trying to call is this:
public ActionResult Withdraw(int personID, int departmentID)
{
.....
}
How can I make this work? Thanks in advance!
Your parameters names do not match those sent by the action link. Try like this:
or update your ActionLink parameter names to match those of the action:
and then:
is going to work.