title: Is there a way to make a @section optional with the asp.net mvc Razor ViewEngine?
body: <p>I have a Page.cshtml similar to the following (that does not work):</p>
  
  <pre><code>@{
      Layout = "../Shared/Layouts/_Layout.cshtml";
      var mycollection = (ViewBag.TheCollection as IQueryable&lt;MyCollectionType&gt;);
  }
  
  &lt;h2&gt;@ViewBag.Title&lt;/h2&gt;
  
  content here
  
  @if (mycollection != null &amp;&amp; mycollection.Count() &gt; 0)
  {    
      @section ContentRight
      {    
          &lt;h2&gt;
              Stuff
          &lt;/h2&gt;
          &lt;ul class="stuff"&gt;
              @foreach (MyCollectionType item in mycollection )
              {
                  &lt;li class="stuff-item"&gt;@item.Name&lt;/li&gt;
              }
          &lt;/ul&gt;
      }
  }
  </code></pre>
  
  <p>As I said, this does not work.  I want to not define the section if there's nothing in the collection.  Is there any way to have something like this work?  If not, what are my other options?  I'm very new to this Razor ViewEngine.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>In my layout i have:</p>
  
  <pre><code>@if(IsSectionDefined("ContentRight")) 
  {
      &lt;div class="right"&gt;
          RenderSection("ContentRight")
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>what i don't want is the div to output when the section is empty.</p>