Tru*_*der 24 c# asp.net-mvc html-helper
您好可以在HTMLHelper扩展方法中访问查询字符串.我们需要根据请求中的查询字符串进行不同的呈现.
Bri*_*ins 37
是的,通过当前上下文,这是HTML Helper上的属性.
public static string DoThis(this HtmlHelper helper)
{
string qs = helper.ViewContext.HttpContext.Request.QueryString.Get("val");
//do something on it
}
Run Code Online (Sandbox Code Playgroud)
当然:
public static MvcHtmlString Foo(this HtmlHelper htmlHelper)
{
var value = htmlHelper.ViewContext.HttpContext.Request["paramName"];
...
}
Run Code Online (Sandbox Code Playgroud)
您可以通过HttpContext对象访问查询字符串.像这样......
string itemVal = System.Web.HttpContext.Current.Request.QueryString["item"];
Run Code Online (Sandbox Code Playgroud)