[英]Using Request.QueryString inside C# View Helper
I want to write a View Helper that will know about the parameters in the URL, but I cannot get access to the Request.QueryString: 我想编写一个View Helper,它将知道URL中的参数,但是我无法访问Request.QueryString:
public static MvcHtmlString SortDirectionArrow(this HtmlHelper html, string column)
{
string desc = Request.QueryString["desc"].ToString();
string currentSortedColumn = Request.QueryString["sort"].ToString();
if (desc == "False" && currentSortedColumn == column)
{
return new MvcHtmlString("desc");
}
else{
return new MvcHtmlString("");
}
}
And you can't just create a new version of HTTPRequestBase because it's an interface: 而且您不能只创建新版本的HTTPRequestBase,因为它是一个接口:
HttpRequest Request = new HttpRequest(); // or
HttpRequestBase Request = new HttpRequestBase();
http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring(v=vs.110).aspx
Try this 尝试这个
var desc = html.ViewContext.HttpContext.Request.QueryString.Get("desc");
Found this on can request querystring be accessed from htmlhelper 发现这可以请求从htmlhelper访问querystring
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.