Reputation: 4746
How to pass model item to @Html.ActionLink text...
@Html.ActionLink( @item.GetLink(),"Controller", "Action" )
this isn't working, if i put it in " " it becomes string. Any ideas?
Upvotes: 1
Views: 2829
Reputation: 8166
Adding to Evgeny Levin's answer, you could also download the MvcContrib library and strongly type your ActionLinks like so
@Html.ActionLink<Controller>(x=>x.Action(), item.GetLink())
I prefer this method over magic strings, and then in my solution configurations I create a new one that mimics Debug but has the value for MvcBuildViews
set to true, and then when you compile, if you have any invalid Links to controller/action pairs, it throws a compiler error. Has saved me many times of pushing out code that doesn't pass required Action parameters
Upvotes: 1
Reputation: 6772
@Html.ActionLink(item.GetLink(), "Action", "Controller")
(without @ character in first parameter, and swap action and controller)
Upvotes: 5