Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Hi Can query string be accessed in HTMLHelper extension methods. We need to render differently depending on the querystring in the request.
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 }
Add a comment
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"];
HttpContext.Current
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.