Adding link tag to homepage using mvc 2

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

      

I have the code above, 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 because item.url outputs the correct value, and if I type in the value manually, that's ok, but using item.url inside the url.content function causes this to happen.

+2


a source to share


2 answers


This is because the main tag was the runat server.



+3


a source


How 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 problems solving it. Why not just refer to it like that?

Edit: Sorry that's actually not the case. WHY your problem is happening but instead just works if you can't figure it out.

0


a source







All Articles