ResolveUrl inserts extra quote
I'm writing my first MVC2 app. 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. 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 href='<%= ResolveUrl("~/Content/Site.css") %>' rel="stylesheet" type="text/css"/>
What comes out (client side, after ASP.NET is through with it):
开发者_StackOverflow中文版<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.
Any ideas?
You should be using the Url.Content
helper:
<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.
ResolveUrl
and runat="server"
are legacy stuff and should not be used in an ASP.NET MVC application.
Since you say this is MVC, you should try and use a helper
<link href="<%= Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css"/>
精彩评论