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
感謝您找到我需要的缺失部分。我沒有想要URL更改,以防用戶在收到錯誤後重新加載頁面,因爲checkout/Method1/{guid}返回了404。我總是把變量放在最後。現在我可以在Get上執行[Route(「checkout/{guid}/{method?}」)],並且仍然允許頁面在刷新後生存。 –