当发送特定的查询字符串参数时,我在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指向第一个请求。那么,如何获得子请求的查询字符串数据呢?
谢谢!/Victor
发布于 2012-01-30 18:07:17
至少到目前为止,我通过使用TempData字典并在使用后删除值解决了这个问题,但我仍然对更好的解决方案感兴趣。似乎应该有一种方法让路由数据通过...
/Victor
发布于 2012-01-05 20:44:05
您可以使用string作为Model,而不是处理查询字符串。
@model string
@if (!string.IsNullOrWhiteSpace(Model) && Model == "Bar") {
//Do something when Foo=Bar (like http://server/route?Foo==Bar)
<html class="bar-class">
}
else {
//Normal html tag
<html>
}
public ActionResult Route(string foo){
return View(foo);
}https://stackoverflow.com/questions/8742594
复制相似问题