Frage

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

War es hilfreich?

Lösung

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;

Andere Tipps

According to answer in this post, http://forums.asp.net/p/1583383/3995794.aspx

you can use:

CodeGeneratorSettings.AddGlobalImport("MyNamespace");
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top