Spider Man Spider Man - 1 year ago 109
ASP.NET (C#) Question

How to pass data to controller action from view in asp.net mvc?

I am creating an asp.net application.

I have an image displayed inside the view of a controller action. When I click on an item in the view (say an image) I would like to pass some data (say ID) to a controller action.

I have the following code in the view:

@Url.Content("ActionName", "Controller");

I would like to send the data into the ActionName action of the Controller controller.

And the controller action looks as follows:

public ActionResult ActionName(string someParam)
return View();

I can call the controller action without a problem but I cannot pass the data. Thanks for help.

Answer Source
<a href='@Url.Action("MyAction", "MyController", new {id = "ID"})'>
    <img src='@Url.Content("~/Content/Images/MyLinkImage.png")' />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download