1
如何從視圖中將一列項目傳遞給控制器以進行保存。我相信我可以使用Viewbag,但我真的不知道如何使用ite來將數據從視圖傳遞到控制器。如何使用ViewBag將View中的數據列表傳遞給控制器
這是我曾嘗試 我的觀點
@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");
}
你是指
?? –不,我沒有modell,即時通訊工作的Dll文件放置在引用 –
沒關係,你仍然可以有一個*視圖模型*。這只是一個類,但不是綁定到數據庫或其他數據存儲。您的數據可以來自任何地方。您只需使用您獲取的數據實例化「視圖模型」類,然後將該類發送到視圖,而不是將所有動態度量都扔到「ViewBag」中。 –