Reputation: 101
For my cancel link, which just basically takes the user back to the page they were at previously, I cannot figure out how to place the passed id value from the URL into the ActionLink
So say I'm here: http://localhost:54636/Project/AddCodeSample/2
and at the bottom of the form, I have a cancel or back button, how can I get that id value from the URL and put it in the ActionLink
@Html.ActionLink("Cancel", "Details", new { id = ??? })
Upvotes: 1
Views: 2210
Reputation: 31033
get the id
from the RouteData
@Html.ActionLink("Cancel", "Details",
new { id = ViewContext.RouteData.Values["ID"] })
Upvotes: 4
Reputation: 43067
The ID should belong to your model:
@Html.ActionLink("Cancel", "Details", new { id = Model.Id })
Upvotes: 2