Hot to escape and unescape @ in mvc?

Total Post:134

 1639  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?

  1. Post:28

    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.

      Modified On Apr-06-2018 01:43:05 AM



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