I have an URL like this /home/action/id
How can I access this id in view?
I have an URL like this /home/action/id
How can I access this id in view?
you can pass it in through viewData;
In your Controller:
public ActionResult Index(string id)
{
ViewData["Name"] = Server.UrlEncode(id);
return View();
}
In your View:
<h1><%= ViewData["Name"] %></h1>
This should work in your view:
<%= this.ViewContext.RouteData.Values["id"] %>
(assuming the route parameter is named "id")