This is a simple MVC app which reads and writes to an Excel file. The functionality can be simplify in these three steps.
- Read list of patients booked for appointment and show them to the user.
- Allow user to check in who came in.
- Update Excel with updated input.
Excel looks as below

Model
public class Appointments
{
public string Facility { get; set; }
public string MRNumber { get; set; }
public string GroupTopic { get; set; }
public string LOC { get; set; }
public bool CheckedIn { get; set; }
}
View Model
public class AppointmentsViewModel
{
public List<Appointments> appointments { get; set; }
}
Index HttpGet passes a View Model Object which shows the 14 rows
public ActionResult Index()
{
AppointmentsViewModel vm = new AppointmentsViewModel();
//Some code is which populates vm with data from Excel
return View(vm);
}
Index HttpPost Action is getting a vm with a list of 14 appointment objects but all properties show null
[HttpPost]
public ActionResult Index(AppointmentsViewModel vm)
{
//Breakpoint
//Some code to update Excel file
}
I place a break point at "Break Point" above, looked into what is passed to vm and it shows all the 14 rows but with null properties
In my view, I made sure I am using a for loop instead of foreach, and that I am using an @Html.DisplayFor for each property in the model. Also my model is declared as
@model Scheduling_Demo.Models.AppointmentsViewModelCode for view is below
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<table class="table" style="align-content:center">
@*<tr>
<th>
@Html.LabelFor(model => model.appointments.FirstOrDefault().Facility)
</th>
<th>
@Html.LabelFor(model => model.appointments.FirstOrDefault().MRNumber)
</th>
<th>
@Html.LabelFor(model => model.appointments.FirstOrDefault().GroupTopic)
</th>*@
@*<th>
@Html.LabelFor(model => model.appointments.FirstOrDefault().Date)
</th>*@
@*<th>
@Html.LabelFor(model => model.appointments.FirstOrDefault().LOC)
</th>
<th>
@Html.LabelFor(model => model.appointments.FirstOrDefault().CheckedIn)
</th>
</tr>*@
@for (int t = 0; t < Model.appointments.Count; t++)
{
<tr>
<td>
@Html.DisplayFor(model => Model.appointments[t].Facility)
</td>
<td>
@Html.DisplayFor(model => Model.appointments[t].MRNumber)
</td>
<td>
@Html.DisplayFor(model => Model.appointments[t].GroupTopic)
</td>
@*<td>
@Html.DisplayFor(model => Model.appointments[t].Date)
</td>*@
<td>
@Html.DisplayFor(model => Model.appointments[t].LOC)
</td>
<td>
@Html.CheckBoxFor(model => Model.appointments[t].CheckedIn)
</td>
</tr>
}
</table>
<input type="submit" name="Submit" value="Submit" class="btn btn-info btn-sm" />
}