0

我在写一个问题,问为什么@Href 不能正确识别路径。

例如

@helper CSS(string cssFile, string media = "screen") {
    <link href="@Href("~/content/stylesheets/" + @cssFile)" rel="stylesheet" type="text/css" media="@media" /> 
}

正在抛出 sereval js 404 错误,试图在其中找到资源

  • http:// 本地主机/内容
  • http://localhost/仪表板/内容

从来没有我想要的:

  • http://localhost/MySite/内容

所以他们我发现了有趣的部分:@Url.Content而不是@Href正常工作!为什么!?

因此这不是更大的问题,问题在于 App_Code @Url 在上下文中不存在。那我可以用什么。

4

1 回答 1

1

MSDN 是你的朋友。来自WebPageRenderingBase.Href方法:

在派生类中重写时,使用指定的参数构建 URL。

而来自UrlHelper.Content 方法

将虚拟(相对)路径转换为应用程序绝对路径。

路径中的波浪号使其成为虚拟路径,显然 @Href() 不理解。

于 2012-05-11T21:47:19.403 回答