Search code examples
asp.net-mvcrazoractionlink

@Html.ActionLink with the item Name as a link


I'm having a hard time on a thing that in the end, must be simple. Using a @Html.ActionLink , all I want is a link with the text of the name from the Model on a table.

Here's what I'm doing:

<td data-th="Nome">@Html.ActionLink( @item.Name , "Details", new { id = @item.UserID })</td>

But I get the error:

HtmlHelper has not applicable method named 'ActionLink' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax


Solution

  • This problem happens when you try to pass dynamic varibles inside extensions methods. This is not supported.

    Problably you have one of these situations:

    1. Your Name property is a dynamic varible. You can try casting it to string: (string) @item.Name
    2. You forgot to add your Model at the top of your View: @model MyModel.