控制器中的HttpPost函数不会被调用

时间:2013-08-23 08:45:17

标签: asp.net-mvc-4

由于某种原因,我的控制器中的3个HttpPost函数没有被调用。我尝试用不同的名字重塑意见,但没有成功。它们都返回到Index视图,而不是运行HttpPost函数。

控制器:

[HttpPost]
public ActionResult OrderIsFinished(string PickUp, string DeliveryBigger, string DeliverySmaller)
    {
        string view = "";

        if (PickUp != null)
        {
            view = "OrderPickUp";
        }

        if (DeliveryBigger != null)
        {
            view = "DeliveryBigger";
        }

        if (DeliverySmaller != null)
        {
            view = "DeliverySmaller";
        }

        return View(view);
    }

查看:

@{
    ViewBag.Title = "OrderIsFinished";
}

@section shoppingcart {
    <p>Shopping Cart</p>
 }

<h2>OrderIsFinished</h2>

@using (Html.BeginForm())
{
    <input type="submit" name="PickUp" value="Ik kom mijn bestelling afhalen" />
    <input type="submit" name="DeliveryBigger" value="Ik wil dat u mijn bestelling levert" />
    <input type="submit" name="DeliverySmaller" value="Ik wil dat u mijn bestelling  levert" />
}

当我在函数上放置断点时,我不在那里它只返回索引视图。

1 个答案:

答案 0 :(得分:2)

尝试隐式点动作和控制器名称

@using (Html.BeginForm("OrderIsFinished","ControllerName",FormMethod.Post))
{
    <input type="submit" name="PickUp" value="Ik kom mijn bestelling afhalen" />
    <input type="submit" name="DeliveryBigger" value="Ik wil dat u mijn bestelling levert" />
   <input type="submit" name="DeliverySmaller" value="Ik wil dat u mijn bestelling  levert" />
}