ASP.NET MVC RC返回Url.Content走错了路 [英] ASP.NET MVC RC returns wrong path for Url.Content

查看:149
本文介绍了ASP.NET MVC RC返回Url.Content走错了路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新这个问题不会在ASP.NET MVC

UPDATE this issue does not exist in the release bits of ASP.NET MVC

我有它运行从 HTTP运行调试器下细的ASP.NET MVC应用程序RC://本地主机:9002 / 但是,当我将它发布到的http://本地主机/ ZOT / 以Url.Content呼叫正在返回不正确的值

I have an ASP.NET MVC RC app which runs fine under the debugger running from http://localhost:9002/ But when I publish it to http://localhost/Zot/ the calls to Url.Content are returning incorrect values.

我有一个像

<script src="<%= Url.Content("~/Scripts/util.js") %>" ...

在发布的站点这将产生:

In the published site this produces:

<script src="Zot/Scripts/util.js" ...

而不是

<script src="/Zot/Scripts/util.js" ...

<script src="Scripts/util.js" ...

我有这样的样式表标记:

I have stylesheet tags like:

<link href="~/Content/Site.css" runat="server" ...

这产生了正确的事情:

<link href="Content/Site.css" ...

为什么Url.Content失败的任何建议。我显然不能把 =服务器&LT;脚本方式&gt; 标签

推荐答案

我倾向于使用罗布科纳的的脚本注册助手

I tend to use Rob Conery's Script Registration helper:

public static string RegisterJS(this System.Web.Mvc.HtmlHelper helper, string scriptLib) {
  //get the directory where the scripts are
  string scriptRoot = VirtualPathUtility.ToAbsolute("~/Scripts");
  string scriptFormat="<script src=\"{0}/{1}\" type=\"text/javascript\"></script>\r\n";
  return string.Format(scriptFormat,scriptRoot,scriptLib);
}

用法:

<%= Html.RegisterJS("myscriptFile.js") %>

正如你可以看到的例子,这里采用VirtualPathUtility来解决脚本目录的URL。这也应有助于绕过标记汤的问题。

As you can see in the example, this uses VirtualPathUtility to resolve the url of the Scripts directory. This should also help to bypass the problem of tag soup.

这篇关于ASP.NET MVC RC返回Url.Content走错了路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆