Monthly Archives: September 2011

MVC & <text> Gotchas

Noticed a few of this lurking around in my teams code base recently, very easy to go unnoticed. Without HTML Validation, anyway.

  1. @helper MyHelper(string foo)
  2. {
  3.     //Good
  4.     @foo
  5.     //Not ‘bad’, just not required as the @foo will just render out. <text></text> is only needed when Razor can’t auto-detect
  6.     <text>@foo</text>
  7. }
  8. <div>
  9.     @* Good *@
  10.     @MyHelper(“Some Nice Message”)
  11.     @*Bad – The <text></text> gets rendered as HTML to the browser*@
  12.     <text>@MyHelper(“Some Nice Message”)</text>
  13. </div>
Share