views:

97

answers:

2
foreach (var item in ((ModelBase)Model).Stylesheets)
{ %>
  <%=item.url %>
  <link rel="stylesheet" type="text/css" href="<%= Url.Content(item.url)%>" />
<% }

I've got the code above running but whenever it outputs the link tag I get the following.

../../Content/Site.css<link rel="stylesheet" type="text/css" href="Views/Shared/%3C%25=%20Url.Content(item.url)%25%3E" />

I'm confused cause the item.url is outputting the correct value, and if I type the value in manually it's ok, but using item.url inside the url.content function causes the above to happen.

A: 

What about just

foreach (var item in ((ModelBase)Model).Stylesheets)
{ %>
  <link rel="stylesheet" type="text/css" href="<%=item.url %>" />
<% }

Depending on how you create the url property in your model, Url.Content is probably having trouble resolving it. Why not just reference it like this?

Edit: Sorry this doesn't really answer WHY your problem is happening, but instead just gives a work around if you can't figure it out.

macca1
Doing as you suggested output's the following. <link rel="stylesheet" type="text/css" href="Views/Shared/%3C%25=item.url%20%25%3E" />
RubbleFord
That's weird. So it's the same problem. Are you sure your <% and %> tags are all opened and closed properly?
macca1
if i stick @ infront of the href attribute all is well, remove and back to the problem. I'm a little confused.
RubbleFord
+1  A: 

It's because the head tag was runat server.

RubbleFord