title: Conditional ASP.NET MVC razor sections
body: <p>I want to define this section only if some property (<code>Model.ReadOnly</code>) is <code>false</code>.</p>
  
  <pre><code>@section toolbar {
      &lt;div class="tool"&gt;
          &lt;div class="row"&gt;
              @Html.ActionLink( Resources.Strings.Edit, "Edit", "Profile" )
          &lt;/div&gt;
          &lt;div class="row"&gt;
              @Html.ActionLink( Resources.Strings.Delete, "Delete", "Profile" )
          &lt;/div&gt;
      &lt;/div &gt;
  }
  </code></pre>
  
  <p>I tried wrapping it up in <code>@if ( !Model.ReadOnly ) {}</code> but it doesn't work.</p>
  
  <p>Is there a way to do this?</p>
  
  <hr>
  
  <p>I do not want to define an empty section (<a href="https://stackoverflow.com/questions/7097162/conditional-asp-net-mvc-razor-sections/7097248#7097248">as @itsmatt suggests</a>), the layout of my page changes whether the section is defined or not (using <code>IsSectionDefined( "toolbar" )</code>).</p>