Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can request querystring be accessed from htmlhelper

Tags:

Hi Can query string be accessed in HTMLHelper extension methods. We need to render differently depending on the querystring in the request.

like image 617
TrustyCoder Avatar asked Nov 10 '10 13:11

TrustyCoder


People also ask

What is request QueryString ()?

The value of Request. QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request. QueryString(parameter).

Which HtmlHelper object method should you use?

It binds the model object to HTML controls to display the value of model properties into those controls and also assigns the value of the controls to the model properties while submitting a web form. So always use the HtmlHelper class in razor view instead of writing HTML tags manually.

What is an HtmlHelper?

An HTML Helper is just a method that returns a string. The string can represent any type of content that you want. For example, you can use HTML Helpers to render standard HTML tags like HTML <input> and <img> tags.


2 Answers

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 } 
like image 50
Brian Mains Avatar answered Oct 31 '22 09:10

Brian Mains


Sure:

public static MvcHtmlString Foo(this HtmlHelper htmlHelper) {     var value = htmlHelper.ViewContext.HttpContext.Request["paramName"];     ... } 
like image 27
Darin Dimitrov Avatar answered Oct 31 '22 09:10

Darin Dimitrov