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:
@try
{
if (item.tbl_computerinfo.FirstOrDefault().teamviewerID != null)
{
<td class="text-center"><a href="javascript:TeamviewerConnect(@Html.DisplayFor(modelItem => item.tbl_computerinfo.FirstOrDefault().teamviewerID)"><img src="~/Content/images/icons/teamviewericon.png" alt='TeamviewerID' border='0' title='@Html.DisplayFor(modelItem => item.tbl_computerinfo.FirstOrDefault().teamviewerID)'></a></td>
}
}
catch (Exception)
{
<td></td>
}
Subsequently this generates hundreds of:
Exception thrown: 'System.NullReferenceException' in System.Web.Mvc.dll
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?