views:

288

answers:

5

Why does the following code:

<%= Html.ActionLink("[Click Here For More +]", "Work", "Home", new { @class = "more" }) %>

render as:

<a class="more" href="/Home/Work?Length=4">[Click Here For More +]</a>

Where is that "Length=4" coming from?

Update

If I remove the new { @class = "more" }, I don't get that Length=4 parameter.

A: 

Do you have a default value for "length" in one of your routes? If the wrong route is selected, use Html.RouteLink instead of ActionLink.

Craig Stuntz
Good catch! IIRC the anonymous type gets converted to a Dictionary.
leppie
A: 

Looks like a DebuggerVisualizer property! But that should not surface.

Anyways 'Length=4' looks suspiciously like an array (with 4 elements). Use the debugger to look for the culprit.

leppie
+3  A: 

I look at the overloads for ActionLink and changed the code to look like:

    <%= Html.ActionLink("[Click Here For More +]", "Work", "Home", null, new { @class = "more" }) %>

Added a "null" for the route values. This seems to work. Not sure though what this might affect.

mattruma
+7  A: 

I've had this happen before, and it never hit me. If you look at the overload you're actually using it's probably not the one you want.

Try...

<%= Html.ActionLink("[Click Here For More +]", "Work", "Home", null, new { @class = "more" }) %>
Chad Moran
Just came to this realization as well!
mattruma
Yeah, this drove me nuts for about an hour before it hit me.
Chad Moran
A: 

The length=4 issue has popped up for me a couple times. The culprit is usually a bad route, either in the definition or the link I am using.

I've gotten in the habit of always double checking those first.

JHappoldt