5

Following is my Html.Actionlink

@Html.ActionLink("Change Team", "Edit", "UserPlayers", new { MatchId = ViewBag.MatchId, UserId = ViewBag.UserId })

When i run the application I get this

http://localhost:50013/UserPlayers/Edit?Length=11

as a link.

I dont know from where is the "Length=11" coming.

MARKAND Bhatt
  • 2,428
  • 10
  • 47
  • 80

1 Answers1

9

You need to add a null as the last parameter:

@Html.ActionLink("Change Team", "Edit", "UserPlayers", new { MatchId = ViewBag.MatchId, UserId = ViewBag.UserId }, null)

Without this, you are using the wrong method overload for Html.ActionLink()

Electric Sheep
  • 3,867
  • 1
  • 29
  • 38
  • 1
    Why would that happen though? It is the wrong overload, the OP is adding HTML attributes to the link, but why would that cause it to append a Length parameter to the url? – JMK Apr 07 '14 at 14:20
  • 3
    @JMK Because without the null, it is most likely hitting this overload of the action link - `public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, Object routeValues, Object htmlAttributes)` and is trying to convert the controller name into a route value (notice userplayers is 11 characters long). Since it is not a dictionary or list, it gets all kinds of confused and outputs `?Length = 11`. MSDN for reference - http://msdn.microsoft.com/en-us/library/dd492124%28v=vs.118%29.aspx – Tommy Apr 07 '14 at 14:23
  • 2
    This answer explains the reason in more detail http://stackoverflow.com/a/824318/2082842 – Electric Sheep Apr 07 '14 at 14:27