@if(Model.LastOrder!= NULL)
{
< H3> Lorem存有:LT; / H3>
}
其他
{
< H3> LOREM LOREM<!/ H3>
} - GT;这里出现错误
通过这个code,我得到一个错误的NullReferenceException
。一切都可以很容易解决,但发生在去年...支架的错误!很奇怪......更有甚者 - 没有什么特别的是错误的信息来帮助我。
为什么我得到这个错误?
下面是我的控制器操作:
[授权]
公众的ActionResult仪表板()
{
XYZ toReturn =新的XYZ {};
返回查看(toReturn);
}
解决方案
尝试删除括号,因为你只有一个行后,如果和其他人,看看会发生什么,这会给你更多的信息,然后。
@if (Model.LastOrder != null)
{
<h3>Lorem ipsum:</h3>
}
else
{
<h3>Lorem lorem!</h3>
} -> here occurs error
With this code, I get an error nullreferenceexception
. Everything could be easy to resolve, but error occurs at... last bracket! Very strange.. and what is more - nothing special is in error info to help me.
Why I get this error?
Here is my controller action:
[Authorize]
public ActionResult Dashboard()
{
XYZ toReturn = new XYZ { };
return View(toReturn);
}
解决方案
Try removing brackets, since you have just one line after if and else, and see what happens, that will give you more information then.