HOT TO ESCAPE AND UNESCAPE @ IN MVC?

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
 1336  View(s)
Ratings:
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?

  1. Mark M

    Post:28

    Points:196
    Re: Hot to escape and unescape @ in mvc?

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!