2010-11-10 2 views

Répondre

36

Oui, grâce au contexte actuel, qui est une propriété de HTML Helper.

public static string DoThis(this HtmlHelper helper) 
{ 
    string qs = helper.ViewContext.HttpContext.Request.QueryString.Get("val"); 
    //do something on it 
} 
5

Vous pouvez accéder à la chaîne de requête via l'objet HttpContext. Comme si ...

string itemVal = System.Web.HttpContext.Current.Request.QueryString["item"]; 
8

Bien sûr:

public static MvcHtmlString Foo(this HtmlHelper htmlHelper) 
{ 
    var value = htmlHelper.ViewContext.HttpContext.Request["paramName"]; 
    ... 
}