简体   繁体   English

ASP.NET IIS服务器警告应用程序错误NullReferenceException

[英]ASP.NET IIS server warning Application Error NullReferenceException

I have MVC project. 我有MVC项目。

It works fine, but sometimes it's throws an exception. 它工作正常,但有时会引发异常。

Here is an IIS screenshot of error. 这是错误的IIS屏幕截图。 在此处输入图片说明

object reference not set to an instance of an object 你调用的对象是空的

object reference not set to an instance of an object 你调用的对象是空的

When the users reload the page, error disappears. 当用户重新加载页面时,错误消失。

   @if (Model.CashboxStatus != null && Model.CashboxStatus.Count > 0)
   {
       foreach (var item in Model.CashboxStatus)
       {
           <td>@item.CashboxName</td>
       }
   }

this is the code populating the Model: 这是填充模型的代码:

public ActionResult Cashboxes()
{
    CashboxesModel model = new CashboxesModel();
    model.Cashboxes = CashboxLogic.GetCashboxes();
    return View(model);
}

It gives an error on first line. 它在第一行给出了错误。

I have no idea why this error appears. 我不知道为什么会出现此错误。 We have about 100 users daily. 我们每天大约有100个用户。

Any ideas? 有任何想法吗?

Try this: 尝试这个:

 @if (Model.CashboxStatus != null && Model.CashboxStatus.Count > 0)
   {
       foreach (var item in Model.CashboxStatus)
       {
           <td>@item.CashboxName ?? string.Empty</td>
       }
   }

Let me know if it works 让我知道是否有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM