title: "System.NullReferenceException' in System.Web.Mvc.dll" is slowing down page load
body: <p>I know why this is occuring, I am looking for a property in my Model that may or may not be there, if it's there it generates some HTML, if it isn't it generates different HTML so I am having to wrap it in a try catch (which is in the middle of a foreach:</p>
  
  <pre><code>@try
  {
      if (item.tbl_computerinfo.FirstOrDefault().teamviewerID != null)
      {
          &lt;td class="text-center"&gt;&lt;a href="javascript:TeamviewerConnect(@Html.DisplayFor(modelItem =&gt; item.tbl_computerinfo.FirstOrDefault().teamviewerID)"&gt;&lt;img src="~/Content/images/icons/teamviewericon.png" alt='TeamviewerID' border='0' title='@Html.DisplayFor(modelItem =&gt; item.tbl_computerinfo.FirstOrDefault().teamviewerID)'&gt;&lt;/a&gt;&lt;/td&gt;
      }
  }
  catch (Exception)
  {
      &lt;td&gt;&lt;/td&gt;
  }
  </code></pre>
  
  <p>Subsequently this generates hundreds of:</p>
  
  <pre><code>Exception thrown: 'System.NullReferenceException' in System.Web.Mvc.dll
  </code></pre>
  
  <p>in the output. This is slowing down the page significantly. Is there a better way to deal with the null reference exception that doesn't slow down the page?</p>