开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜