Nullreferenceexception on top .. bracket?

@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 can be easily resolved, but an error occurs ... the last bracket! Very strange .. and what's more - nothing special about the error information to help me.

Why am I getting this error?

Here is my controller action:

[Authorize]
public ActionResult Dashboard()
{
     XYZ toReturn = new XYZ { };
     return View(toReturn);
}
+2
source share
1 answer

Try removing the brackets since you only have one line after if and else and see what happens, which will give you more information.

-1
source

All Articles