Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC - Get ViewContext from helper method

I would like to create a static helper method that I can call from a view.

Is it possible for a helper method to have access to the current ViewContext without needing to explicitly pass the ViewContext to the method as a parameter?

Something like HttpContext.Current except for ViewContext.

like image 629
Keith Avatar asked Feb 19 '10 01:02

Keith


1 Answers

public static class XTenshuns
{
    public static string MyHtmlHelper(this HtmlHelper helper)
    {
        // it's right here -> helper.ViewContext
    }
}
like image 100
pdr Avatar answered Oct 03 '22 03:10

pdr