– How to get the ID from URL

I am using MVC.

I have edit page url like {controller}/Edit/2

so on the view page how can I get the ID from this URL?

I'm gonna put a link to redirect to some page with sending above ID.


<%=Html.ActionLink("name", "Action", "Controller", new{ ID = ? } ) %>

Best Solution

you can get it from the RouteData object

 <%=Html.ViewContext.RouteData.Values["id"].ToString() %>