Search code examples
asp.net-mvcparametersroutes

How do I access a route parameter in my ASP.NET MVC view?


I have an URL like this /home/action/id

How can I access this id in view?


Solution

  • This should work in your view:

    <%= this.ViewContext.RouteData.Values["id"] %>
    

    (assuming the route parameter is named "id")