Reputation: 8618
I'm writing some custom helpers the current one involves a sort of "datagrid control" type helper and i seem to have hit a bit of a hurdle.
if i was in a razor view i coud something like Html.EditorFor(someExpression) and i can't seem to find a way to do that within the context of my helper code within my custom helper.
Effectively i'm trying to call a helper from within a helper.
Here's an example in the most basic form i can think of:
public static MvcHtmlString Test(dynamic Model)
{
return new MvcHtmlString( Html.textBox(Model.SomeProperty) )
}
Any ideas ?
I figured out how dumb this was when I added a using statement like this to my code ...
using Html = System.Web.Mvc.Html;
Talk about simple ... note to self ... pay attention to framework !!!
Upvotes: 1
Views: 403
Reputation: 12478
Make your helper method into a extension method instead.
public static MvcHtmlString Test(this HtmlHelper html, dynamic Model)
{
return new MvcHtmlString( html.textBox(Model.SomeProperty) )
}
You call this by first have a using of the namespace where (the class where) the method is and then just Html.Test(Model)
Upvotes: 1