I am developing a C# MVC application. I am using a View and Display template to manage the User Interface. The Users are able to edit the data presented on multiple pages. I am having an issue posting the Datatable data from all pages to the Controller. The List object in the Model returned to the Controller contains the correct number of rows, but the column values of all the rows except the rows on the last edited page are null. How do I post all of the data to the Controller?
**Code from my View:**
@model TreatyMilestonesViewModel
@{
ViewData["Title"] = "Treaty Milestones";
}
@using (@Html.BeginForm())
{
@*These were put here for two reasons;
1. They are within a
to eliminiate HTML warning 1503 "Unexpected start tag"
2. They were initially moved within the first column to eliminate the warning, but having them there broke the checkbox
sorting feature hence I moved them to their own cell.*@
@Html.HiddenFor(modelItem => modelItem.TreatyMilestoneId)
@Html.HiddenFor(modelItem => modelItem.TreatyId)
@Html.HiddenFor(modelItem => modelItem.MilestoneId)
@Html.HiddenFor(modelItem => modelItem.TreatyName)
**Code from Controller:**
``` [HttpPost]
public ActionResult SaveMilestones(TreatyMilestonesViewModel _model)
{
// retrieve the as-is state of currently assigned Milestones
List currentlyAssignedMilestones = GetCurrentlyAssignedMilestones(_model.SelectedTreatyId);
// Let's create this now and we will assign the TreatyId and TreatyName to be passed back to the View after processing is completed
TreatyMilestonesViewModel vm = new TreatyMilestonesViewModel()
{
//SelectedTreatyId = _model.TreatyMilestonesList[0].TreatyId,
//SelectedTreatyName = _model.TreatyMilestonesList[0].TreatyName
SelectedTreatyId = _model.SelectedTreatyId,
SelectedTreatyName = _model.SelectedTreatyName
};
foreach (TreatyMilestonesList tmlrec in _model.TreatyMilestonesList)
{
...