Chris Pfohl
Chris Pfohl

Reputation: 19064

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):

<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?

Upvotes: 2

Views: 537

Answers (2)

Chase Florell
Chase Florell

Reputation: 47397

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"/>

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038950

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.

Upvotes: 2

Related Questions