Why is MVC actionlink not rendering correctly?
Asked Answered
P

1

1

I am passing this :

<%: Html.ActionLink("Edit", "EditCRMRequest", "CRM", new { Id = item.Id })%>

and I am getting in browser :

http://something.com/CRM/EditCRMRequest?Length=3

with Error Code :

The parameters dictionary contains a null entry for parameter 'Id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult EditCRMRequest(Int32)' in 'ApricaCRMEvent.Controllers.CRM.CRMController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

If I explicitly write this in browser it works fine:

http://something.com/CRM/EditCRMRequest?Id=3
Pournaras answered 4/2, 2013 at 13:19 Comment(1)
Like the answer below mentioned, if you look at the method overload that you are using it is expecting htmlAttributes and not routeValues. That is why you get the ?length=3 on your query string.Ironsides
G
5

Correct way:

<%: Html.ActionLink("Edit", "EditCRMRequest", "CRM", new { Id = item.Id },null)%>

No overload method like this:

Html.ActionLink(string text, string action, string controller, object routeValues)

If you write like above, Lenght=3 is represent "CRM". Controller name behave as routeValues

Correct method is:

Html.ActionLink(string text, string action, string controller, object routeValues, object htmlAttributes)
Gaudette answered 4/2, 2013 at 13:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.