Spider Man Spider Man - 8 months ago 49
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.

<a href='@Url.Action("MyAction", "MyController", new {id = "ID"})'>
    <img src='@Url.Content("~/Content/Images/MyLinkImage.png")' />