开发者

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 a开发者_开发问答n 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


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;


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

you can use:

CodeGeneratorSettings.AddGlobalImport("MyNamespace");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜