When there is no match by registrationID
, Enumerable.FirstOrDefault returns null
. So profiles
in public ActionResult detail(int id)
is null then and null
is consequently passed into the view.
You cannot access Model.profile.photo
, when Model.profile
is null. Try to add null check:
@if(Model.profile != null &&
!string.IsNullOrWhiteSpace(Model.profile.photo))
{
//...
}
else {
<p>This user does not have a profile</p>
}