views:

276

answers:

1

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.

Thanks for any help. -Keith

A: 
public static class XTenshuns
{
    public static string MyHtmlHelper(this HtmlHelper helper)
    {
        // it's right here -> helper.ViewContext
    }
}
pdr
Can I only do it via extension methods then? What if I wanted a plain ol' helper method?
Keith
Well, it couldn't be a plain old helper method. If you wanted to make it more lightweight, you could rip off some of the code from HtmlHelper to roll something similar... even then you'd need to add that as a property somewhere, probably a custom ViewPage. Nah, it's been written this way for a reason. Why so against HtmlHelper?
pdr