【发布时间】:2011-08-24 20:44:59
【问题描述】:
我正在查看Url 助手扩展方法上的article。我尝试关注这篇文章,但结果在布局中没有可见的扩展方法(共享 *.chtml 文件)。
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类在哪个命名空间中?
标签: asp.net-mvc-3 url extension-methods helpers