具有相同操作名称的AspCore多个发布操作

时间:2017-08-31 16:29:13

标签: asp.net-core

我有一个结帐页面,有多种付款方式。每个方法都有自己的局部视图,包含自己的模型。我试图在每个不同的方法上保持url相同,所以如果有错误,url不会改变。有没有办法实现这个目标?谢谢你的帮助,我一直在考虑这个问题。

CheckOut Model

 public class CheckoutForm
{

    public Method1Form method1Form { get; set; }
    public Method2Form method2Form { get; set; }
    public Method3Form method3Form { get; set; }
}

CheckOut Controller

[HttpGet]
[Route("checkout/{guid}")]
public IActionResult Checkout([FromRoute] String guid)
{
    ....
    return View(model);
}
[HttpPost]
[Route("checkout/{guid}")]
public IActionResult Checkout([FromRoute] String guid, Method1 model)
{
    ....
    //Some Error Condition Triggered
    return View(checkoutmodel);
}
[HttpPost]
[Route("checkout/{guid}")]
public IActionResult Checkout([FromRoute] String guid, Method2 model)
{
    ....
    //Some Error Condition Triggered
    return View(checkoutmodel);
}
[HttpPost]
[Route("checkout/{guid}")]
public IActionResult Checkout([FromRoute] String guid, Method3 model)
{
    ....
    //Some Error Condition Triggered
    return View(checkoutmodel);
}

类似问题没有答案https://stackoverflow.com/questions/42644136

1 个答案:

答案 0 :(得分:0)

你做不到。 Route Engine无法区分这3种方法。

您可以在网址末尾添加一些内容,以使其与众不同。

[HttpPost]
[Route("checkout/{guid}/paypal")]
public IActionResult Checkout([FromRoute] String guid, Method1 model)
{
    ....
}

[HttpPost]
[Route("checkout/{guid}/authorizenet")]
public IActionResult Checkout([FromRoute] String guid, Method2 model)
{
    ....
}
相关问题