I am trying to return the results of a table back to the controller for further manipulation. Once returned to the controller the value shows as null. In the past I have been able to use @Html.HiddenFor to return the values but it doesn't seem to be working in this instance. Not sure what I am doing wrong here. Any help is greatly appreciated.
@model IEnumerable<Project.Models.Item>
@{
ViewBag.Title = "Welcome to The Project";
}
@using (Html.BeginForm("UpdateQuality", "Home", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
<div class="row">
<div class="form-group">
<table class="table table-bordered">
<tr>
<th>@Html.DisplayNameFor(m => m.Name)</th>
<th>@Html.DisplayNameFor(m => m.SellIn)</th>
<th>@Html.DisplayNameFor(m => m.Quality)</th>
</tr>
@for (int i = 0; i < Model.Count(); i++)
{
<tr>
<td>@Html.DisplayFor(m => m.ElementAt(i).Name)</td>
<td>@Html.DisplayFor(m => m.ElementAt(i).SellIn)</td>
<td>@Html.DisplayFor(m => m.ElementAt(i).Quality)</td>
@Html.HiddenFor(m => m.ElementAt(i).Name)
@Html.HiddenFor(m => m.ElementAt(i).SellIn)
@Html.HiddenFor(m => m.ElementAt(i).Quality)
</tr>
}
</table>
<div class="form-group">
<div style="margin-top: 50px">
<input type="submit" class="btn btn-primary" value="Advance Day"/>
</div>
</div>
</div>
</div>
}
And here is the controller which returns null.
public ActionResult UpdateQuality(List<Item> Items )
{
return View("Index", (object)Items);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…