How can I visualize a variable correctly without confusing the Razor engine?

I am trying to render CSS using the Razor viewer (yes, I know, it was designed for XML-style languages).

My template looks like this:

#@Model.ID { top: @Model.Toppx; left: @Model.Leftpx; } 

Of course, this fails because Toppx and Leftpx arent model properties, Top and Left . I cannot highlight the space (e.g. @Model.Top px; ), because although this works in terms of patterns, its invalid CSS and Firefox ignore it.

Other template languages ​​(Freemarker, Velocity) will support it as: ${Model.Top}px; , and even the usual ASP.NET viewing engine supports it as: <%=Model.Top%>px;

How can I get this behavior in Razor? I tried: @:<text>@Model.Top</text>px , but this did not compile.

I also tried: @ Model.Top@ :px; but that didn't work either.

Note. I am using standalone Razor (located at http://razorengine.codeplex.com/ ) with Mono 2.10

thanks

+4
source share
1 answer

Try expressing the block of code with parentheses:

 #@(Model.ID) { top: @(Model.Top)px; left: @(Model.Left)px; } 
+7
source

All Articles