Asp.net-mvc – How to get the current route ID within a View from the URL (ASP.NET MVC)

asp.net-mvc

Within the view that is returned from a URL such as /Controller/Action/1 (assuming the default route of controller/action/id), how can I get access to the ID from within the View?

I don't want to have to add it to the ViewData dictionary at the action level when handling the request.

Best Solution

I think this is what you're looking for:

<%=Url.RequestContext.RouteData.Values["id"]%>