开发者

Url helper's invisible inside the layout. ASP.NET MVC 3

I was looking at the article on Url helpers extension methods. And I tried to follow the article but as result none of written extension methods were visible in the layout (shared *.chtml file).

public static class UrlHelperExtensions
{
    public static String Image(this System.Web.Mvc.UrlHelper helper, String fileName)  
    {             
         return helper.Content("~/Content/Images/" + fileName);  
    }
    public static String Stylesheet(this System.Web.Mvc.UrlHelper helper, String fileName)
    {
        return helper.Content("~/Content/Stylesheets/" + fileName);
    }
    public static String Script(this System.Web.Mvc.UrlHelper helper, String fileName)
    {
        return helper.Content("~/Content/Scripts/" + fileName);
    }
}

// inside the layout I tried to use this:
<link href="@Url.Content("Site.css")" rel="st开发者_StackOverflowylesheet" type="text/css"/> 

How do I make Url extension methods visible inside the layout?

Thanks!


Ensure you have a reference to your namespace where you are using the helpers.

So if you created the class UrlExtensions in MyClassLib.Web, add @using MyClassLib.Web to the top of your .cshtml file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜