MVC を使用して、コントローラーの GET 関数で VM を作成し、それをビューに渡します。
[Themed]
public ActionResult OrderManufacturedProducts(int id)
{
QBProductRecord QBproduct = _qbproductService.GetById(id);
OrderManufacturedProductsVM model = new OrderManufacturedProductsVM(QBproduct);
return View(model);
}
次に、ビュー:
@model System.ViewModels.OrderManufacturedProductsVM
@{
Script.Require("ShapesBase");
Layout.Title = T("Manufactured Orders").ToString();
}
@using (Html.BeginFormAntiForgeryPost())
{
<fieldset>
<table class="items" summary="@T("This is a table of the manufactured products to be ordered")">
<colgroup>
<col id="Col1" />
<col id="Col2" />
<col id="Col3" />
</colgroup>
<thead>
<tr>
<th scope="col"> ↓</th>
<th scope="col">@T("Name")</th>
<th scope="col">@T("Description")</th>
</tr>
</thead>
<tbody>
<tr>
<td>@Model.QBProduct.ProductName</td>
<td>@Model.QBProduct.StockLevel</td>
<td><input id="Order" name="NoToOrder" type="text" value="0" onchange=""/></td>
</tr>
</tbody>
</table>
<div class="align right"><button type="submit" name="command" value="Save">Order</button></div>
</fieldset>
}
したがって、ユーザーは注文番号を入力します。入力フィールドで送信をクリックすると、投稿に戻ります。
[HttpPost, ActionName("OrderManufacturedProducts")]
public ActionResult OrderManufacturedProductsPOST(int id, int NoToOrder)
{
// OrderManufacturedProductsVM model = new OrderManufacturedProductsVM(QBproduct);
// return View(model);
return Index();
}
インデックスページに戻りたいのですが、それは私に言っています
Server Error in '/OrchardLocal' Application.
The model item passed into the dictionary is of type 'System.ViewModels.ManufacturedProductsVM', but this dictionary requires a model item of type 'System.ViewModels.OrderManufacturedProductsVM'.
投稿で同じ VM を使用する必要がありますか? 私がしたいのは、更新が行われた後にインデックス ページをリロードすることだけです。
注: レコードの更新は正常に機能しています。後で表示する正しいページを取得できません。