OdeToCode IC Logo

Razor Tip #1

Thursday, January 6, 2011

The Razor parser is smart. For example, if you want to display an email address, you can enter the following:


... and Razor will happily output Serial@Model.com into the output - it recognizes the email address.

But what if you want to output a serial number?


Unfortunately, Razor still thinks you have an email address and outputs "Serial@Model.SerialNumber". In a few rare cases you have to be more explicit and let the parser know where the C# code begins and ends.


But a prettier approach is to use an “explicit code nugget” with parentheses:


Shahnawaz Thursday, January 6, 2011
Nice tip!

Waiting for your next .net tip(s).

Gravatar Eber Irigoyen Thursday, January 6, 2011
won't that omit the @ in the last example?
Gravatar Eber Irigoyen Thursday, January 6, 2011
nevermind, that's what you want
Gravatar scott Thursday, January 6, 2011
@Eber - right, trying to display:
luke Wednesday, January 19, 2011
If you did want an @ you can escape the @ by entering @@

so would have:
Gravatar scott Wednesday, January 19, 2011
@luke: Good one.
Comments are closed.