This question already has an answer here:
这个问题在这里已有答案:
- What is a NullReferenceException, and how do I fix it? 33 answers
什么是NullReferenceException,我该如何解决? 33个答案
I am getting error "object reference not set to an instance of an object " on this line:
我在这一行收到错误“对象引用未设置为对象的实例”:
@Html.DropDownListFor(m => m.Query.Area, Model.Area, "Select Area", new { @class = " QueryFormTextBox" })
Any suggestions?
3 个解决方案
#1
0
Your m.Query
is null, so m.Query.Area
throw null reference exception. Init Query in controller (to new Query()) and all will be work.
你的m.Query为null,所以m.Query.Area抛出null引用异常。在控制器中启动查询(到新的Query()),所有都将工作。
#2
0
Try to alert the parameters using javascript just before your statement to check if all values are coming as expected or they are null. One more possibility is that the Model itself is not set in the view.
尝试在语句之前使用javascript警告参数,以检查所有值是否按预期进行或者为空。另一种可能性是模型本身未在视图中设置。
Like:
alert(Model.Area);
#3
0
You should make sure that Model.Area
is instantiated before passing it to your View and type of IEnumerable<SelectListItem>
您应确保在将Model.Area传递给您的View和IEnumerable
#1
0
Your m.Query
is null, so m.Query.Area
throw null reference exception. Init Query in controller (to new Query()) and all will be work.
你的m.Query为null,所以m.Query.Area抛出null引用异常。在控制器中启动查询(到新的Query()),所有都将工作。
#2
0
Try to alert the parameters using javascript just before your statement to check if all values are coming as expected or they are null. One more possibility is that the Model itself is not set in the view.
尝试在语句之前使用javascript警告参数,以检查所有值是否按预期进行或者为空。另一种可能性是模型本身未在视图中设置。
Like:
alert(Model.Area);
#3
0
You should make sure that Model.Area
is instantiated before passing it to your View and type of IEnumerable<SelectListItem>
您应确保在将Model.Area传递给您的View和IEnumerable