How do I access a route parameter in my ASP.NET MVC view?
I have an URL like this /home/action/id
开发者_JS百科
How can I access this id in view?
This should work in your view:
<%= this.ViewContext.RouteData.Values["id"] %>
(assuming the route parameter is named "id")
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>
精彩评论