ScottG
ScottG

Reputation: 319

ASP.NET MVC - Adding querystring "length=" to ActionLinks?

I have a few ActionLinks that when rendered are getting a length key/value added that appears to indicate the number of characters of the controller name. How can this be removed?

Upvotes: 29

Views: 11441

Answers (4)

Shyam Poovaiah
Shyam Poovaiah

Reputation: 334

If you are passing 'routeValues',

Make sure that 'htmlAttributes' is set to null.

 Html.ActionLink("Title", "Action", "Controller", new {}, null )

Else wrong overload of AcitonLink is picked.

Upvotes: 1

Dan Diplo
Dan Diplo

Reputation: 25339

At a guess, you are probably using the wrong overload of Html.ActionLink and are adding to the route parameters instead of the HTML attributes. You need to add a NULL as the fourth parameter before your specify the HTML attributes. Something like:

 Html.ActionLink("Title", "Action", "Controller", null ,new { title = "Title"} )

Post your code if this doesn't work.

Upvotes: 45

John Farrell
John Farrell

Reputation: 24754

Check to see if your using the right overload for Html.ActionLink.

They get tricky because they take any object, even anonymous ones, and transform those into route value dictionaries or html attributes depending on the overload your using. Since it will run and compile fine if you mess these two up its hard to tell if your using the right overload.

Upvotes: 2

Paul Creasey
Paul Creasey

Reputation: 28824

you need stick stick an extra empty object parameter in before the htmlattributes, something like this off the top of my head

 html.actionlink("a","b","c",new {},new {@class = "d"})

Upvotes: 3

Related Questions