2017-08-31 74 views
0

我有一个具有多种付款方式的结帐页面。每种方法都有自己的局部视图,包含自己的模型。我试图让每个不同的方法保持相同的url,所以如果有错误,URL不会改变。有没有办法做到这一点?感谢您的帮助,我一直在考虑这一段时间。AspCore具有相同操作的多个发布操作名称

CheckOut的型号

public class CheckoutForm 
{ 

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

CheckOut的控制器

[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

回答

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) 
{ 
    .... 
} 
+0

感谢您找到我需要的缺失部分。我没有想要URL更改,以防用户在收到错误后重新加载页面,因为checkout/Method1/{guid}返回了404。我总是把变量放在最后。现在我可以在Get上执行[Route(“checkout/{guid}/{method?}”)],并且仍然允许页面在刷新后生存。 –

相关问题