I am receiving the error:
System.NullReferenceException occurred HResult=-2147467261 Message=Object reference not set to an instance of an object when attempting to access a view.
The error is pointing to this line:
<span>@(d.AcceptPropagation == null ? string.Empty : "Accepts Propagation")</span>
I set a breakpoint at the foreach loop and stepped through to find where the null was occurring. I do not receive an error until the 5th time through the loop and I am getting a null at DocumentTemplate. I thought I was handling the null correctly. Do I need additional null checks? Do I need to handle this differently? Below is the view. I also changed "" to string.Empty in the code.
@if (criteria != null)
{
foreach (var d in criteria)
{
<tr>
<td style="width: 80px;">
<a class="blue button edit-template" data-reveal-id="edit-form" id="@d.ID">Edit</a>
</td>
<td>
<strong>@(d.DocumentTemplate == null ? string.Empty: d.DocumentTemplate.Name)</strong><br />
<div>@d.GroupCode</div>
<span>@d.PlanCode</span>
<span>@d.SubPlanCode</span>
<span>@d.ActionCode</span>
<span>@d.AdmitTerm</span>
<span>@d.AdmitTypeCode</span>
<span>@d.ProgramCode</span>
<span>@d.ResidentCode</span>
<span>@(d.V19 == true ? "V19" : string.Empty)</span>
<span>@(d.A23 == true ? "A23" : string.Empty)</span>
<span>@(d.AcceptPropagation == null ? string.Empty : "Accepts Propagation")</span>
<div><a href="@Url.Content(d.DocumentTemplate.Path)">@(Url.Content(d.DocumentTemplate.Path)==null? string.Empty : d.DocumentTemplate.Path)</a></div>
</td>
</tr>
}
}