mvc model binding and null checking
<p>I have a simple model as below </p>

<pre><code>public class TestModel
{
    public string property1 {get;set;}
    public string property2 {get;set;}
}
</code></pre>

<p>On my razor view i have two textboxes thats mapping to these two properties. 
Only one of the text box is a required field and other one can be left empty.(that is either property1 or property2 can be entered or both can be entered..however both cannot be left blank) </p>

<p>My controller action method is quite simple</p>

<pre><code>     public ActionResult MyMethod(TestModel tmodel)
     {
          //code fails on this null check..object reference not set to instance of object 
          if (!string.IsNullOrEmpty(tmodel.property1))
          {
          }
      }
</code></pre>

<p>If i do this on my attribute of my model, the above statement works..why is null alone failing ?</p>

<pre><code> [DisplayFormat(ConvertEmptyStringToNull = false)]
</code></pre>

<p>What i dont understand is why is the string.IsNullOrEmpty fails? </p>

<p>Here is the view..</p>

<pre><code>     &lt;div class="form-group"&gt;
        @Html.LabelFor(m =&gt; m.property1, new { @class = "col-sm-3 control-label" })
        &lt;div class="col-sm-4"&gt;
            @Html.TextBoxFor(m =&gt; m.property1, new { @class = "form-control"})
        &lt;/div&gt;          
    &lt;/div&gt;

    &lt;div class="form-group"&gt;
         @Html.LabelFor(m =&gt; m.property2, new { @class = "col-sm-3 control-label" })
         &lt;div class="col-sm-4"&gt;
        @Html.TextBoxFor(m =&gt; m.property2, new { @class = "form-control" })
    &lt;/div&gt;
</code></pre>

<p>Thanks for your thoughts...</p>