我正在尝试制作一个股票盘点应用程序,我的视图使用一个编辑器加载我的所有股票。我的控制器没有从视图中获取任何数据?
我希望能够同时编辑我所有的股票?我怎样才能做到这一点
型号代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace FlatSystem.Models
{
public class Stock
{
public int ID { get; set; }
public string Item_Name { get; set; }
public int Actual_Stock { get; set; }
public int Wanted_Stock { get; set; }
}
}
查看代码
@model IEnumerable<FlatSystem.Models.Stock>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<div class="sidemenu">
<div class="sidemenu-heading">
ReStock
</div>
<div class="div-body">
<table>
<tr>
<th>
Item Name
</th>
<th>
Wanted Stock
</th>
<th>
Stock On Hand
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Item_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Wanted_Stock)
</td>
<td>
<div class="editor-field">
@Html.EditorFor(modelItem => item.Actual_Stock)
@Html.ValidationMessageFor(modelItem => item.Actual_Stock)
</div>
</td>
@Html.HiddenFor(modelItem => item.ID)
</tr>
}
</table>
</div>
</div>
<input type="submit" value="Submit" />
}
控制器代码
[HttpPost]
public ActionResult ReStock(List<Stock> stock)
{
foreach (var item in stock)
{
if (ModelState.IsValid)
{
GR.InsertOrUpdate(item);
}
}
GR.Save();
return RedirectToAction("Restock");
}