0
我正在查看Url
助手擴展方法上的article。我試圖按照這篇文章,但結果沒有任何書面擴展方法在佈局中顯示(共享* .chtml文件)。Url助手在佈局中不可見。 ASP.NET MVC 3
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="stylesheet" type="text/css"/>
如何在佈局中顯示Url
擴展方法?
謝謝!
你可以發佈你的代碼,顯示你的嘗試? –
您的示例代碼在佈局文件中調用'Url.Content'。當你用'Url.Stylesheet()'替換它時會發生什麼?你的'UrlExtensions'類是什麼名字空間? –