0

使用 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">&nbsp;&darr;</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'.

那么我需要在我的帖子中使用相同的虚拟机吗?我要做的就是在更新完成后重新加载索引页面。

注意:记录上的更新工作正常,我只是无法在之后显示正确的页面。

4

1 回答 1

1

在您的OrderManufacturedProductsPOST操作中,您应该重定向到您想要返回的操作。像这样:

[HttpPost, ActionName("OrderManufacturedProducts")]
public ActionResult OrderManufacturedProductsPOST(int id, int NoToOrder)
{
    // OrderManufacturedProductsVM model = new OrderManufacturedProductsVM(QBproduct);
    // return View(model);

    return RedirectToAction("Index");
}
于 2013-09-16T10:42:58.930 回答