简体   繁体   English

ResolveUrl 插入额外的引号

[英]ResolveUrl inserts extra quote

I'm writing my first MVC2 app.我正在编写我的第一个 MVC2 应用程序。 I've got my master page working beautifully, and when I run it locally it functions exactly like I want it to.我的母版页运行良好,当我在本地运行它时,它的功能完全符合我的要求。

My problem is that I'm deploying it on a server that has a whole bunch of Applications.我的问题是我将它部署在具有一大堆应用程序的服务器上。 ResolveUrl seems to be misbehaving. ResolveUrl 似乎行为不端。 I get the correct path, but for whatever reason something is inserting an extra quote, or dropping the quotes I have.我得到了正确的路径,但无论出于何种原因,某些东西正在插入额外的引号,或者删除我拥有的引号。

Here's my <link> :这是我的<link>

<link href='<%= ResolveUrl("~/Content/Site.css") %>' rel="stylesheet" type="text/css"/>

What comes out (client side, after ASP.NET is through with it):结果是什么(客户端,在 ASP.NET 完成之后):

<link href=/vcdemo/PhotoManager/Content/Site.css" rel="stylesheet" type="text/css" />

Obviously it's not what I want.显然这不是我想要的。 When I correct the quotes in Firebug the site displays correctly.当我更正 Firebug 中的引号时,该站点会正确显示。

Any ideas?有任何想法吗?

You should be using the Url.Content helper:您应该使用Url.Content助手:

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css"/>

Also as it seems that you are using the WebForms view engine make sure you have removed any runat="server" attributes that might be present on the <head> tag.此外,您似乎正在使用 WebForms 视图引擎,请确保您已删除可能存在于<head>标记上的所有runat="server"属性。

ResolveUrl and runat="server" are legacy stuff and should not be used in an ASP.NET MVC application. ResolveUrlrunat="server"是遗留的东西,不应在 ASP.NET MVC 应用程序中使用。

Since you say this is MVC, you should try and use a helper既然你说这是 MVC,你应该尝试使用助手

<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM