Why isn't this MVC Html Helper extension method working?

Posted by Blankman on Stack Overflow See other posts from Stack Overflow or by Blankman
Published on 2010-06-07T14:47:44Z Indexed on 2010/06/07 14:52 UTC
Read the original article Hit count: 401

Filed under:
|
|
|

My base controller looks like:

public abstract MyBaseMasterController<TMasterViewModel> : Controller
{

}


public MyMasterController: MyBaseMasterController<SomeThingModel>
{

}

Extension method:

public static string DoSomething(this HtmlHelper htmlHelper)
{
    StringBuilder sb = new StringBuilder();

    sb.Append("var cnwglobals = {");

    var controller = htmlHelper.ViewContext.Controller as MyMasterController;
    if (controller == null)
    {
    }

    return sb.ToString();
}

In my view I do:

<% Html.Dosomething(); %>

I get an error:

CS1061: 'System.Web.Mvc.HtmlHelper<Blah.Models.ViewModelForMasterWrapper<Blah.Models.MasterViewModel>>' does not contain a definition for 'DoSomething' and no extension method 'DoSomething' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<Blah.Models.ViewModelForMasterWrapper<Blah.Models.MasterViewModel>>' could be found (are you missing a using directive or an assembly reference?)

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET