4

By mistake I took the wrong constructor in an ActionLink:

 @Html.ActionLink("Show Customer", "Load", "Customer", new {Model.Id });

The error is, that the last parameter is of type htmlAttributes and not of routeValues (as expected). So the right constructor would have been:

 @Html.ActionLink("Show Customer", "Load", "Customer", new {Model.Id }, null);

So I do not need to solve that problem... I just wonder, when I used the wrong constructor, my routeValue must have been interpreted as an htmlAttribute.

I was just surprised that it results in a length-Parameter. The generated code was:

/Customer/Load?Length=7

Just by curiosity: Where does the length=7 come from?

Ole Albers
  • 8,715
  • 10
  • 73
  • 166

2 Answers2

6

This is overload of ActionLink, which is getting hit:

public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes);

So your only route value is string, controller name, "Customer", which has public property Length, 8 symbols. And routeValues is picking with reflections all public properties of object, which was passed to it.

And worth to mention, that your link will receive html attribute Id='whatever_id_model_holds', since 4th parameter is mapped to htmlAttributes.

Dmytro
  • 1,590
  • 14
  • 14
  • You seem to be right, which IS REALLY SURPRISING, because "Customer" has EIGHT characters.... But. In the original Code it was "Partner" instead of "Customer". I changed the code to make it more anonymous and readable. So. "+1" for coding knowledge, "-1" for math.... :) – Ole Albers Nov 21 '13 at 16:09
  • 1
    @OleAlbers, you're right. Checked my old code, without making real calculations manually. Fixed) – Dmytro Nov 21 '13 at 16:12
2

TAKEN FROM https://stackoverflow.com/a/4360565/7720

The ActionLink override you are using matches to the (string linkText, string actionName, Object routeValues, Object htmlAttributes) override. So your "Customer" value is being passed to the routeValues parameter. The behavior of this function with respect to this parameter is to take all public properties on it and add it to the list of route values used to generate the link. Since a String only has one public property (Length) you end up with "length=7".

Community
  • 1
  • 1
Romias
  • 13,783
  • 7
  • 56
  • 85