I have read Object reference not set to an instance of an object. and What does “Object reference not set to an instance of an object” mean? posts but still not able to get help because my case is different.
Simple Code
<script>
var PatientId;
var DoctorId;
if(isPatient && @Model.Patient != null) {
PatientId = @Model.Patient.Id;
DoctorId = userConnection.User.Id;
} else if(!isPatient && @Model.Doctor != null) {
DoctorId = @Model.Doctor.Id; // Right here I get ERROR
PatientId = userConnection.User.Id;
}
</script
Error
System.NullReferenceException: Object reference not set to an instance of an object.
In my case either @Model.Patient
or @Model.Doctor
will be null
.
Right now I know that @Model.Doctor
is null
, but I am already checking its null
condition above. How to cater this problem ?
} else if(!isPatient && && @Model.Doctor != null) { – Ivaylo Stoev Jan 22 '17 at 14:56