I'm using a helper class to build my hyperlink. The markup looks like this:
<a href='/controller/action?id=val'></a>
This is the same markup that the Html.ActionLink()
produces. However, if I use the Html.ActionLink()
, the id is accepted as a parameter in the method inside the controller. If I just generate the a
tag in a string like the above I get the error below when I try to define the method with an id parameter:
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult' ... To make a parameter optional its type should be either a reference type or a Nullable type. Parameter name: parameters
- Is there a way to use
Html.ActionLink()
in my helper class? - Why is there a difference between the two techniques?
Here's my controller action:
public ActionResult AssignmentAdd(int id)
{
return View();
}