开发者

c# razor url parameter from view

Why does Request["parameterName"] returns null w开发者_如何学Pythonithin the view? I know I can get it from the controller but I have to make a little check in the View. I am using ASP.NET MVC 3.


You can use the following:

Request.Params["paramName"]

See also: When do Request.Params and Request.Form differ?


I've found the solution in this thread

@(ViewContext.RouteData.Values["parameterName"])


@(ViewContext.RouteData.Values["parameterName"])

worked with ROUTE PARAM.

Request.Params["paramName"]

did not work with ROUTE PARAM.


If you're doing the check inside the View, put the value in the ViewBag.

In your controller:

ViewBag["parameterName"] = Request["parameterName"];

It's worth noting that the Request and Response properties are exposed by the Controller class. They have the same semantics as HttpRequest and HttpResponse.


@(HttpUtility.UrlDecode(Request.Query["parameterName"].FirstOrDefault()) ?? "")
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜