Home > DeveloperSection > Forums > Hot to escape and unescape @ in mvc?
Tanuj Kumar

Total Post:134

Points:940
Posted on    October-29-2014 11:56 PM

 ASP.NET MVC ASP.NET MVC  Mvc 
Ratings:


 1 Reply(s)
 879  View(s)
Rate this:
I am trying to make dynamic CSS import:

@foreach (string cssUrl in Model.Css)

{

    @@import url(@Url.Content(cssUrl));

}

However this does not work, the @import is escaped but @Url... should not be! What now?



Kamlakar Singh
Kamlakar Singh

Total Post:28

Points:196
Posted on    October-29-2014 11:59 PM

You could place plain text in a <text> tag:

@foreach (string cssUrl in Model.Css)

{

    <text>@@import url(</text> @Url.Content(cssUrl)<text>);</text>

}

And this might work as well (haven't tried though):

@foreach (string cssUrl in Model.Css)

{

    @@import url(@:@Url.Content(cssUrl));

}

Note that the <text></text> tag will not be rendered.


Don't want to miss updates? Please click the below button!

Follow MindStick