Alan Domingues
Alan Domingues

Reputation: 91

@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

Upvotes: 1

Views: 2261

Answers (2)

Thiago Ferreira
Thiago Ferreira

Reputation: 651

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.

Upvotes: 1

Hardik Gondalia
Hardik Gondalia

Reputation: 3717

For MVC 3+ version

@Html.ActionLink( @item.Name , "Action_Name", "Controller_Name" , new { id = @item.UserID }, null)

OR

@Html.ActionLink( @item.Name , "Action_Name", "Controller_Name" , new { @item.UserID }, null)

ID is no longer require in mvc 3+ versions

Upvotes: 0

Related Questions