我已阅读Object reference not set to an instance of an object.和What does “Object reference not set to an instance of an object” mean?个帖子,但仍然无法获得帮助,因为我的情况不同。
简单代码
<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
错误
System.NullReferenceException: Object reference not set to an instance of an object.
在我的情况下,@Model.Patient
或@Model.Doctor
将为null
。
现在我知道@Model.Doctor
是null
,但我已经检查了上面的null
条件了。如何解决这个问题?