ASP.NET MVC RC returns wrong path for Url.Content

前端 未结 2 1880
青春惊慌失措
青春惊慌失措 2021-01-12 14:53

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

I have an ASP.NET MVC RC app which runs fine under the debugger running from htt

2条回答
  •  生来不讨喜
    2021-01-12 15:07

    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="\r\n";
      return string.Format(scriptFormat,scriptRoot,scriptLib);
    }
    

    Usage:

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

    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.

提交回复
热议问题