Hi Can query string be accessed in HTMLHelper extension methods. We need to render differently depending on the querystring in the request.
37
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
}
8
Sure:
public static MvcHtmlString Foo(this HtmlHelper htmlHelper)
{
var value = htmlHelper.ViewContext.HttpContext.Request["paramName"];
...
}
5
You can access the querystring via the HttpContext object. Like so...
string itemVal = System.Web.HttpContext.Current.Request.QueryString["item"];