I have a web application that upload csv file and display the details rows.
In the first view i create a table and I need choose a few rows then in the action controller I do some staff and return to the second view and there I create a table with the chosen rows from the first view.
Now if I choose in the first view the rows 1, 3, 5 I get in the second view the rows 1, 2, 3 or in the first view i choose 4, 6 in the second view I get 1, 2.
public class DetailsExcelFile
{
public int NumberClient { get; set; }
public string NameClient { get; set; }
public int Amount { get; set; }
public string Email { get; set; }
public string ContactPerson { get; set; }
public bool IsSelectedRow { get; set; }
public bool NeedEmail { get; set; }
}
The ViewModelForExcel class always with the latest list.
public class ViewModelForExcel
{
public List<DetailsExcelFile> DetailsExcelFileList { get; set; }
public DetailsExcelFile ObjectDetailsExcelFile { get; } = new DetailsExcelFile();
public ViewModelForExcel()
{
}
}
The vies: first:
@model SendLinks.ViewModels.ViewModelForExcel
@{
ViewBag.Title = "FileDetails";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("ChooseItems", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
if (@ViewBag.Message != null)
{
<div style="border: 1px solid red">
@ViewBag.Message
</div>
}
<table id="DetailsExcelChoose" class="table-responsive text-right">
<thead>
<tr>
<th><input type="checkbox" id="checkAll" /></th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.IndexRow, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.InvoiceNumber, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.NumberClient, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.NameClient, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.Amount, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.ContactPerson, new { @readonly = "readonly" })</th>
</tr>
</thead>
<tbody>
@for (var i = 0; i < Model.DetailsExcelFileList.Count(); i++)
{
<tr>
<td>@Html.CheckBoxFor(a => a.DetailsExcelFileList[i].IsSelectedRow, true)</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].IndexRow, new { @class = "wideIndexRow" })</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].InvoiceNumber)</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].NumberClient, new { @class = "wideIndexRow" })</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].NameClient)</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].Amount, new { @class = "wideIndexRow" })</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].ContactPerson)</td>
</tr>
}
</tbody>
<tr>
<td></td>
<td>
<input type="submit" value="choose" />
</td>
<td></td>
</tr>
</table>
}
The action in the controller:
[HttpPost]
[ValidateAntiForgeryToken]
[Route("ChooseItems")]
public async Task<ActionResult> ChooseItemsAsync(ViewModelForExcel i_Obj)
{
if (ModelState.IsValid)
{
//do some staff....
return View("~/Views/Home/UpdateFileDetails.cshtml", new ViewModelForExcel() { DetailsExcelFileList = manipulateFile.GetDetailsExcelFileListToUpdate() });// manipulateFile is object that have the list from i_Obj after it doing something :)
}
return HttpNotFound();
}
The second view:(UpdateFileDetails.cshtml)
@model SendLinks.ViewModels.ViewModelForExcel
@{
ViewBag.Title = "UpdateFileDetails";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("UpdateItems", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
if (@ViewBag.Message != null)
{
<div style="border: 1px solid red">
@ViewBag.Message
</div>
}
<table id="DetailsExcelChoose">
<thead>
<tr>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.IndexRow, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.InvoiceNumber, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.NumberClient, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.NameClient, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.Amount, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.Email, new { @readonly = "readonly" })</th>
<th class="RightToLeft">@Html.LabelFor(a => a.ObjectDetailsExcelFile.ContactPerson, new { @readonly = "readonly" })</th>
</tr>
</thead>
<tbody>
@for (var i = 0; i < Model.DetailsExcelFileList.Count(); i++)
{
<tr>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].IndexRow, new { @class = "wideIndexRow" })</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].InvoiceNumber)</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].NumberClient, new { @class = "wideIndexRow" })</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].NameClient)</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].Amount, new { @class = "wideIndexRow" })</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].Email, new { required = "required" })</td>
<td>@Html.TextBoxFor(a => a.DetailsExcelFileList[i].ContactPerson)</td>
</tr>
}
</tbody>
<tr>
<td>
<input type="submit" value="Update" />
</td>
<td></td>
<td></td>
</tr>
</table>
}
I try to debugging all the actions that I do in the controller and everything work fine. just the view make problems.
Update the question