Reputation: 26018
I have an edit application view, and it can be found at the following URL:
http://localhost:17262/Application/EditApplication/1
1 equals the application ID.
Also on the page I have a link that goes to another view to add an assistant for the application. I want to pass it the application ID so that the new assistant can be "linked" to this application. How would I get the value of 1 and add it to my action link? This is what I have in my HTML so far:
<%: Html.ActionLink("Add New Assistant", "Create", "Assistant", new { applicationID = "id" }, null) %>
Please could someone advise?
Thanks
Upvotes: 3
Views: 3575
Reputation: 5194
If you use the default routing settings
Request.RequestContext.RouteData.Values["id"]
should do what you want.
you can also pass the id from the controller to the view using the ViewData
ViewData["applicationID"] = 1; //or ApplicationModel.Id or whatever
and use it in your view
<%: Html.ActionLink("Add New Assistant", "Create", "Assistant", new { applicationID = ViewData["applicationID"] }, null) %>
or in a strongly typed view use the viewmodel to pass the id:
<%: Html.ActionLink("Add New Assistant", "Create", "Assistant", new { applicationID = Model.ApplicationID }, null) %>
Upvotes: 5