.netrazorasp.net-mvc-3htmlextensions

ASP.Net MVC 3 - Html Extensions


I'm playing around with Razor + MVC 3 and have a really simple scenario... Basically I'm trying to create a very basic HTML helper but I'm getting the following exception:

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

The code for the extension looks like this:

    public static MvcHtmlString ScriptCss(this HtmlHelper htmlHelper, string path)
    {
        return MvcHtmlString.Create(String.Format("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\" />", path));
    }

Any ideas where I am going wroung?

Cheers Anthony


Solution

  • I'd check a couple of things, are you

    a) making sure the parent class of your extension method is public?

    and b) import your respective namespace:

     @using MyNamespace;