我已经从数据库中创建了一个项目列表。这些显示正确。现在我想将更改后的布尔值保存到我的数据库中。我怎样才能将所有这些项目接收到我的控制器,以便我可以通过 foreach 或其他方式遍历它们?
控制器
public class ItemController : Controller
{
private SocialGEOContext db = new SocialGEOContext();
public ActionResult ApproveItems()
{
Utility ut = new Utility();
IEnumerable<Item> items;
items = ut.GetAllDistrictItems();
return View(items);
}
[HttpPost]
public ActionResult ApproveItems( ??? )
{
???
}
在我试过的 HttpPost
[HttpPost]
public ActionResult ApproveItems( IEnumerable<Item> ViewItems )
{
foreach (Item item in ViewItems)
{
var testje = item.ItemTitle;
}
return View();
}
但是 ViewItems 是空的
页
@model IEnumerable<LibModels.Item>
@{
ViewBag.Title = "ItemsByDistrict";
}
<h2>All items from district</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<table>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ItemID)
</td>
<td>
@Html.DisplayFor(modelItem => item.ItemTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.ItemCreateddate)
</td>
<td>
@Html.DisplayFor(modelItem => item.ItemDescription)
</td>
<td>
@Html.EditorFor(modelItem => item.ItemApproved)
</td>
</tr>
}
</table>
<p>
<input type="submit" value="Edit" />
</p>
</fieldset>
}