Ortund
Ortund

Reputation: 8245

Why is my MVC actionlink taking me to the URL with a Length querystring value?

There isn't really much I can do in the way of explanation on this one.

Simply put, I'm trying to render this link:

<a class="button active-button" href="/Home/Register">Register</a>

My ActionLink looks like this:

@Html.ActionLink("Register", "Register", "Home", htmlAttributes: new { @class = "button active-button" })

Which renders this link:

<a class="button active-button" href="/Home/Register?Length=4">Register</a>

I don't understand where the QueryString value is coming from so where have I made my mistake?

Upvotes: 3

Views: 36

Answers (2)

Puzzled
Puzzled

Reputation: 15

This is due to wrong overload as mentioned in another answer.If you are confused about which overload should be used then you can use visual studio intellisence.

In MVC3+ you have this

Html.ActionLink("Register", 
                "Register",   // <-- ActionMethod
                "Home",  // <-- Controller Name.
                 null, // <-- Route arguments..you don't need this
                new {@class = "button active-button"}// <-- htmlArguments
                )

Upvotes: 0

NightOwl888
NightOwl888

Reputation: 56849

This is happening because you are calling the wrong overload of ActionLink.

@Html.ActionLink("Register", "Register", "Home", null, new { @class = "button active-button" }) 

Upvotes: 2

Related Questions