Erin Drummond
Erin Drummond

Reputation: 5526

How can razor be used to expand CSS templates?

I am trying to use Razor to generate some CSS. However, I am running into problems with conflicting syntax. Eg:

@section css {
<style type="text/css">
    #@(Model.InstanceName) {
        top: @(Model.Properties["top"])px;
    }
</style>
}

What is happening is that the first closing curly brace ( } ) is being interpreted by Razor as the end of the @section, instead of the last one. How can I make Razor ignore it?

Upvotes: 0

Views: 330

Answers (2)

Erin Drummond
Erin Drummond

Reputation: 5526

I found the problem. It appears this is a bug in ASP.NET MVC4 Beta. That will teach me for using beta software.

It works as expected in ASP.NET MVC 3

Upvotes: 3

SLaks
SLaks

Reputation: 887245

Your code works for me.

This would only happen if your HTML tags are imbalanced.
You should either balance your tags or prefix that line with @: (or wrap in <text> tags) to prevent it from parsing the }.

Upvotes: 0

Related Questions