asp.net-mvc-3razorcompiler-directives

Pre-processing equivalent for views in RAZOR/MVC 3


I'm looking for the equivalent of an

#if DEBUG
   //view elements to show just for debug builds
#if

for views in MVC3/Razor. What's the idiomatic method for implementing this type of a setup?


Solution

  • That's too messy IMO. Views should be dumb, and focused on rendering HTML, not making build-based decisions.

    Set properties in your view model if debug is configured, and render them out in the View.

    If the properties are null (e.g non-debug), nothing will get rendered.