开发者

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"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜