我如何将项目列表从视图发送到控制器以保存它。我相信我可以使用 Viewbag,但我真的不知道如何使用 ite 将数据从视图传递到控制器。
这就是我尝试过的我的观点
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>ProductionOrderItem</legend>
<div class="editor-label">
@Html.Label("ProducrionOrderNo");
</div>
<div class="editor-field">
@Html.TextBox("ProductionOrderNo", ViewBag.ProductionOrder as int)
</div>
<div class="editor-label">
@Html.Label("OrderName")
</div>
<div class="editor-field">
@Html.TextBox("OrderName", ViewBag.ProductionOrder as string)
</div>
<div class="editor-label">
@Html.Label("OrderDate")
</div>
<div class="editor-field">
@Html.TextBox("OrderDate", ViewBag.ProductionOrder as DateTime)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
和我的控制器
[HttpPost]
public ActionResult Create(FormCollection collection)
{
ProductionRegistration pr = new ProductionRegistration();
ProductionItem poi = new ProductionItem();
poi = Viewbag.ProductionOrder;
pr.SaveOrder(Conn, poi);
return RedirectToAction("Index");
}