Using MVC 4.
When an order is placed on our site the order is POSTed to:
[HttpPost]
public ActionResult ConfirmOrder(ABCModel model)
{
//Do Stuff
return View("ConfirmedOrder", model);
}
The user sees the Confirmed page.
If they press REFRESH in their browser, the page POSTs again.
Is there a way in MVC to prevent the POST again, perhaps in a redirect or some sort?
Instead of doing
return View("ConfirmedOrder", model)
separate your confirmation logic into a controller and do
return RedirectToAction("ConfirmOrderActionName")
.
Here your ConfirmOrderActionName
controller can retrieve the order information from the data store and sent it to its own view, or your ConfirmedOrder
view.
P.S.
Note that RedirectToAction()
helper method also returns a type of ActionResult
(just like returning a View()
does).
If you're interested see:
MSDN: Controllers and Action Methods in ASP.NET MVC Applications and MSDN: ActionResult Class
You might want to redesign the logic a little bit. It is a command problem in Shopping Cart check out.
Here is how most Shopping Cart works -
Step 1. Cart (Create a Session here)
... Shipping, Payment and so on
Step 2: ConfirmOrder - Get (If no Session, redirect to Cart page.)
ConfirmOrder - Post (If no Session, redirect to Cart page. If valid and
check out successful, redirect to Complete page)
Step 3: Complete (Clear the Session)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With