Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind data as parameter to ActionLink?

Tags:

c#

asp.net-mvc

I have problem with ActionLink. I'd like to pass to my ActionLink parameter for my MessageController, for Edit action: to generate somthing like this /MessagesController/Edit/4

So I have ListView control with binding expression:

and how to pass this ID to ActionLink as parameter to my Controller Edit action? This doesn't work: , null) %>
like image 386
Dariusz Avatar asked Dec 23 '22 13:12

Dariusz


1 Answers

In MVC you are not supposed to databind from the view in the way that you have. The data that you want to pass to the ActionLink method needs to be added to ViewData in your controller. Then in the view you retrieve it from ViewData:

<%= Html.ActionLink("My Edit Link", "Edit", "Message", new { id = ViewData["id"] }) %>
like image 76
liammclennan Avatar answered Jan 10 '23 18:01

liammclennan