title: In Mvc 3 razor view what is the best way to conditionally render html based on Nulls in the model
body: <p>This is I am sure an easy question but I am having trouble figuring this out.</p>
  
  <p>I want to do something like this....</p>
  
  <blockquote>
  <pre><code>@(string.IsNullOrEmpty(Model.CustomerUrl) ? "" : &lt;a href="@Model.CustomerUrl"&gt;Click me&lt;/a&gt;)
  </code></pre>
  </blockquote>
  
  <p>This snippet doesn't work.</p>
  
  <p>The mixing of the html with the razor syntax and the inclusion of quotes in the attributes of the tags is making it hard to figure out. </p>
  
  <p>I love razor except figuring out this kind of stuff is really tripping me up.</p>
  
  <p>I would love to just not render the following at all if the CustomerUrl was null or empty...</p>
  
  <pre><code>&lt;p class="customerLink links"&gt;&lt;a href="@Model.CustomerUrl"&gt;@Model.CustomerName&lt;/a&gt;&lt;/p&gt;
  </code></pre>
  
  <p><strong>EDIT</strong><br>
  This is still not working for me...thanks for the suggestion though.  </p>
  
  <p>My issue is that the above code is ALREADY in a Razor Code Block.  Here is my actual code that I cannot figure out...</p>
  
  <p><strong>EDIT NUMBER TWO - THE following code is now working</strong></p>
  
  <pre><code>    @if (Model.Count() &gt; 0)
      {
          foreach (var partner in Model)
          {
              &lt;li&gt;
                  @Html.ActionLink(@partner.CustomerName, "Details", "Customer", new { id = Customer.AID }, null)&lt;br /&gt;
                  @partner.Street&lt;br /&gt;
  //this is what i cannot figure out!!
                  @if(!string.IsNullOrEmpty(partner.Phone))
                      {
                          @partner.Phone@:&lt;br /&gt;
                      }
                  @partner.Distance&lt;br /&gt;
              &lt;/li&gt;
          }
      }
  </code></pre>
  
  <p>I preceded the nested block (the if) with the @ symbol.  Then the markup <br /> I had to delimit with @: Then it worked.</p>
  
  <p>It seems yesterday when I tried to use a nested razor code block I got a compiler error BECAUSE I preceded it with an @.  So now I am more confused than ever.  </p>
  
  <p>In fact...if I tried to surround my @partner.Phone with quotes like this... <code>"@partner.Phone"@:&lt;/ br&gt;</code> I get another compiler error. Razor is great when it works but when it doesn't it is very confusing.</p>
  
  <p>Seth</p>