can request querystring be accessed from htmlhelper
Hi Can query string be accessed in HTMLHelper extension methods. We need to render differently depending on the querystring in the reques开发者_开发知识库t.
Yes, through the current context, which is a property on HTML Helper.
public static string DoThis(this HtmlHelper helper)
{
string qs = helper.ViewContext.HttpContext.Request.QueryString.Get("val");
//do something on it
}
Sure:
public static MvcHtmlString Foo(this HtmlHelper htmlHelper)
{
var value = htmlHelper.ViewContext.HttpContext.Request["paramName"];
...
}
You can access the querystring via the HttpContext object. Like so...
string itemVal = System.Web.HttpContext.Current.Request.QueryString["item"];
精彩评论