gpt4 book ai didi

c# - 在 Asp.net MVC 中出现类似 "Object reference is not set to Reference of the Object"的错误

转载 作者:行者123 更新时间:2023-11-30 16:12:29 24 4
gpt4 key购买 nike

<分区>

我有模型课

 namespace Project1.Models
{
public class GetTimesheetList
{
public List<TimesheetModel> GetTimesheetDetails { get; set; }
}
public class TimesheetModel
{
ResLandEntities res = new ResLandEntities();

public int WEEK_CAL_ID { get; set; }
public int COMP_ID { get; set; }
public int RES_ID { get; set; }
public int PROJ_ID { get; set; }
public string DESCR { get; set; }
public int TEXTBOX_WEEK_ID { get; set; }

public int EMP_ID { get; set; }


public int SUN_HRS { get; set; }


public int MON_HRS { get; set; }


public int TUE_HRS { get; set; }


public int WED_HRS { get; set; }


public int THU_HRS { get; set; }


public int FRI_HRS { get; set; }


public int SAT_HRS { get; set; }


public string START_DATE { get; set; }

public string END_DATE { get; set; }

public string IS_DELETED { get; set; }

public string CR_BY { get; set; }

}
}

In View I Have written like

   @model Project1.Models.GetTimesheetList
@using (Html.BeginForm("Timesheet", "Employer", FormMethod.Post))

{

@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table class="list-chiller-record">
@for (int i = 0; i < Model.GetTimesheetDetails.Count; i++)// GETTING NULL REFERENCE HERE.
{
if (i == 0)
{
<tr class="chiller-record-template" style="display: none">
<td>@Html.TextBoxFor(m => m.GetTimesheetDetails[i].SUN_HRS, new { style = "width:50px; height:30px;", @class = "sunhrs" })
</td>
<td>@Html.TextBoxFor(m => m.GetTimesheetDetails[i].MON_HRS, new { style = "width:50px; height:30px;", @class = "monhrs" })
</td>
<td>@Html.TextBoxFor(m => m.GetTimesheetDetails[i].TUE_HRS, new { style = "width:50px; height:30px;", @class = "tuehrs" })
</td>
<td>@Html.TextBoxFor(m => m.GetTimesheetDetails[i].WED_HRS, new { style = "width:50px; height:30px;", @class = "wedhrs" })
</td>
<td>@Html.TextBoxFor(m => m.GetTimesheetDetails[i].THU_HRS, new { style = "width:50px; height:30px;", @class = "thurhrs" })
</td>
<td>@Html.TextBoxFor(m => m.GetTimesheetDetails[i].FRI_HRS, new { style = "width:50px; height:30px;", @class = "frihrs" })
</td>
<td>@Html.TextBoxFor(m => m.GetTimesheetDetails[i].SAT_HRS, new { style = "width:50px; height:30px;", @class = "sathrs" })
</td>
</tr>
}
}

///已编辑。

从 Controller

      public Employer Controller
{
public ActionResult Timesheet()
{
return View();
}
}

这有什么问题

          "Object reference not set to reference of the object"

我从模型类调用列表并返回列表元素的“计数”,它应该返回没有。列表中的元素,但返回空引用。请任何人帮助我,我该如何解决??

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com