Create an htmlhelper instance of a different type

I have an extension method HtmlHelper that can take one template parameter of type T. Next, inside the method, I want to return to the editors for some fields an object marked with a special attribute. The problem is that I call this method, for example, from HtmlHelper <TModel>, but inside the method I need an instance of HtmlHelper <T> to use its editor method. I tried to create a default instance as follows:

var html = new HtmlHelper<T>(new ViewContext(), new ViewPage());  

but of course this does not work.
So how can I create the correct instance?

+5
source share
1 answer

I do not think you need to repeat it.

You tried something like this:

public static IHtmlString MyExtensionMethod<T>(this HtmlHelper html, T model) where T : IMyModel
{
    //your logic that returns a new HtmlString with html.TextBox for example
}
0

All Articles