Currently, I am working with .NET MVC in conjunction with AngularJS. My objective is to return the newly created order after initiating a post request to place an order, to a separate view.
The scenario involves two views: Purchase Success and Purchase Fail. Below is the Angular post request code snippet:
$http.post('/Home/PlaceOrder/', placeOrderViewModel)
.then(function (response) {
if (response != null) {
window.location = '/Home/PurchaseSuccess';
} else {
window.location = '/Home/PurchaseFail';
}
}, function () {
alert('error');
});
Furthermore, here is the method within my MVC controller:
public ActionResult PlaceOrder(PlaceOrderViewModel viewModel)
{
}
This method takes in a view model from the Angular post request, performs certain operations, and then ideally should return either the purchase success or purchase fail view along with the order model for a successful order creation.
return View("~/Views/Home/PurchaseSuccess.cshtml", order);
return View("~/Views/Home/PurchaseFail.cshtml");
However, the process of returning the view does not seem to be functioning correctly. It appears that MVC is unable to handle the transition between views when the initial request was made via Angular. The redirect implemented in the Angular success handler works smoothly without any model data being passed along.
In essence, I simply need to successfully redirect to the purchase success view while also passing the necessary model information.
Thank you for taking the time to address this!
EDIT: Additionally, below are the controller methods for both purchase success and purchase fail scenarios:
public ActionResult PurchaseSuccess()
{
return View();
}
public ActionResult PurchaseFail()
{
return View();
}