I Have Model Class
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; }
}
}
and 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>
}
}
///Edited.
and From Controller
public Employer Controller
{
public ActionResult Timesheet()
{
return View();
}
}
What is wrong in this getting like
"Object reference not set to reference of the object"
I am Calling List from Model Class and returning "count" of the elements of the list, it should return no. of the elements in the list, but returning null reference instead. Please help me anyone, How do I Fix it ??