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.

0

1 Answer 1

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()

Sign up to request clarification or add additional context in comments.

3 Comments

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 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 - msdn.microsoft.com/en-us/library/dd492124%28v=vs.118%29.aspx
This answer explains the reason in more detail stackoverflow.com/a/824318/2082842

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.