RubbleFord
RubbleFord

Reputation: 7636

Adding a link tag to a masterpage with mvc 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.

Upvotes: 2

Views: 644

Answers (2)

RubbleFord
RubbleFord

Reputation: 7636

It's because the head tag was runat server.

Upvotes: 3

macca1
macca1

Reputation: 9681

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.

Upvotes: 0

Related Questions