title: How to check model string property for null in a razor view
body: <p>I am working on an <code>ASP.NET MVC 4</code> application. I use <code>EF 5</code> with code first and in one of my entities I have :</p>
  
  <pre><code>public string ImageName { get; set; }
  public string ImageGUIDName { get; set; }
  </code></pre>
  
  <p>those two properties which are part of my entity. Since I may not have image uploaded these values can be null but when I render the view passing the model with <code>ImageName</code> and <code>ImageGUIDName</code> coming as <code>null</code> from the database I get this :</p>
  
  <p><strong><code>Exception Details: System.ArgumentNullException: Value cannot be null.</code></strong></p>
  
  <p>The basic idea is to provide different text for the user based on the fact if there is picture or not:</p>
  
  <pre><code>            @if (Model.ImageName != null)
              {
                  &lt;label for="Image"&gt;Change picture&lt;/label&gt;
              }
              else
              { 
                  &lt;label for="Image"&gt;Add picture&lt;/label&gt;
              }
  </code></pre>
  
  <p>So when the above code got me that error I tried with <code>string.IsNullOrEmpty(Model.ImageName)</code> and also <code>Model.ImageName.DefaultIfEmpty() != null</code> but I got the exact same error. It seems that I can not just set y entity property as nullable:</p>
  
  <pre><code>public string? ImageName { get; set; } //Not working as it seems
  </code></pre>
  
  <p>So how can I deal with this?</p>