I have a razor display template in MVC3 for an address. Here is an example of the coding I’ve used for one line of the address:
@Model.City<text>,</text>
When I place the comma straight after the variable name, it creates a syntax error. Adding the <text> tag around the comma fixes the problem, but it seems a bit messy when most of the razor code is so neat and concise.
Is there a neater and more concise way to do this?
Edit: This piece of code is inside an if block. I didn’t realise, but it turns out this affects how razar parses stuff.
You can wrap the expression in parentheses to explicitly tell the parser where it ends:Alternatively, you could use two expressions:
EDIT: I misunderstood your situation.
Inside a code block (
@if,@for,@{ ... }), the Razor parser is expecting code, not markup (or text).If you put an HTML tag or
<text>tag in, it will know that you’re giving it markup.However, arbitrary text, such as
,, is assumed to be C# source.Instead of using the
<text>tag to tell the parser that you’re giving markup, you should use@: