0

I don't understand why if I add parameters on my @Html.ActionLink() the root doesn't go in the correct way.

In fact if I use this

@Html.ActionLink("Torna alla lista", "Index", "VwOpenOrders")

The program rooting on "/VwOpenOrders" that is what I aspect.

If I add parameter like this

@Html.ActionLink("Torna alla lista", "Index", "VwOpenOrders", new { SearchLV = TempData["SearchLV"]})

It go on root "/VwFases?Length=12", where "VwFase" is the controller of the page where I launch the action link.

Please someone can help me? what am I doing wrong?

Thank you

Dona
  • 78
  • 8
  • You using the wrong overload - it need to be `@Html.ActionLink("Torna alla lista", "Index", "VwOpenOrders", new { SearchLV = TempData["SearchLV"]}, null)` - note the 5th parameter –  Sep 03 '18 at 09:08
  • This is more proper as dupe: https://stackoverflow.com/questions/824279/why-does-html-actionlink-render-length-4. – Tetsuya Yamamoto Sep 03 '18 at 09:16
  • Sorry for the duplicate question – Dona Sep 03 '18 at 15:00

3 Answers3

0

You should use the below instead

@Html.ActionLink("Torna alla lista", "Index", "VwOpenOrders", new { SearchLV = TempData["SearchLV"]},null)

by adding additional parameter of "null" to get the right overload for the method

0

The overload of ActionLink you should try to use is the following:

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

That being said you should change you code as below:

@Html.ActionLink("Torna alla lista"
                , "Index"
                , "VwOpenOrders"
                , new { SearchLV = TempData["SearchLV"]}
                , null)

For a detailed listing of ActionLink overloads please have a look here.

Christos
  • 53,228
  • 8
  • 76
  • 108
0

You're actually using this ActionLink overload:

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

The third parameter is routeValues, not controllerName, so that Length=12 is length of string VwOpenOrders supplied to it. What you should do is using controller parameter:

@Html.ActionLink("Torna alla lista", "Index", new { controller = "VwOpenOrders" }, new { SearchLV = TempData["SearchLV"]})

Or using overload which accepts 5 arguments:

@Html.ActionLink("Torna alla lista", "Index", "VwOpenOrders", new { SearchLV = TempData["SearchLV"]}, null)
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61