对象引用未设置为对象的实例 - 模型绑定

时间:2017-01-22 14:52:00

标签: javascript c# jquery asp.net-mvc asp.net-mvc-4

我已阅读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.Doctornull,但我已经检查了上面的null条件了。如何解决这个问题?

0 个答案:

没有答案