What I have:

MyAppCodeHelpers.cshtml

@using MyCustomHelperExtensions
@helper MiniForm(SomeClassCommonToBothViewModels o, int arg1, string arg2)
{
    @Html.MyCustomHelperTextBox(l => o.MemberName, o.MemberName, "etc");
}

MyCustomHelperExtensions.cs

public static string MyCustomerHelperTextBox(this HtmlHelper html, string textValue, string otherStuff)
{
    return "<input type='text'>Whatever - doesn't matter</input>";
}

FirstView.cshtml

@model MyNamespace.FirstViewModel

@MyAppCodeHelpers.MiniForm(Model.InstanceOfSomeCommonObject, 1, "first")

SecondView.cshtml

@model MyNamespace.SecondViewModel
@MyAppCodeHelpers.MiniForm(Model.InstanceOfSomeCommonObject, 2, "second")

What I get:

CS1061: 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'MyCustomHelperTextBox' and no extension method 'MyCustomHelperTextBox' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

I've found several blog posts and questions touching on similar scenario but none of them really addresses my situation.

Is what I'm trying to do possible? And if so, what am I doing wrong?

Cheers, .pd.

Related posts

Recent Viewed