【发布时间】:2012-01-05 12:37:37
【问题描述】:
当发送特定的查询字符串参数时,我正在我的 html 标记上设置一个类,现在我正在这样做(Razor 视图母版页):
@if (HttpContext.Current.Request.QueryString.AllKeys.Contains("Foo") && HttpContext.Current.Request.QueryString["Foo"] == "Bar") {
//Do something when Foo=Bar (like http://server/route?Foo==Bar)
<html class="bar-class">
}
else {
//Normal html tag
<html>
}
正常的请求可以正常工作,但是当我使用 RenderAction 调用页面时就不行了,比如
//Other view, the one requested by the user
@Html.RenderAction("Index", "Route", new {Foo="Bar"})
环顾四周后,我意识到只有一个实际的 HttpContext,这意味着 HttpContext.Current 指向第一个请求。那么 - 如何获取子请求的查询字符串数据?
谢谢! /维克多
【问题讨论】:
-
您在
new {Foo = "Bar" }中缺少引用。
标签: c# razor query-string renderaction asp.net-mvc