I want to use an actionlink to call a controller. My URL is
localhost:16252/Concert/Index/9
.
I want to call create controller and send id (9) to the controller. How to access the id (9) from address bar by actionlink?
I want to use an actionlink to call a controller. My URL is
localhost:16252/Concert/Index/9
.
I want to call create controller and send id (9) to the controller. How to access the id (9) from address bar by actionlink?
ActionLink has one overload that allows you to specify routevalues
MSDN Link here
@Html.ActionLink("LinkText", "Action", "Controller", new {Id= 9}, null)
For Passing from View you have to use overload which takes parameter of RouteValueDictionary:
@Html.ActionLink("Link Text","MyAction", "My", new {id= 9},null)
and in your controller:
public class MyController
{
public ActionResult MyAction(int id)
{
// do something
return View();
}
}
Using this overload of Html.ActionLink()