I am using .NET MVC and AngularJS. After making a post request to place an order, I need to return the order that was created to a different view.
I have two views. Purchase Success and Purchase Fail. Here is the post request in Angular:
$http.post('/Home/PlaceOrder/', placeOrderViewModel)
.then(function (response) {
if (response != null) {
window.location = '/Home/PurchaseSuccess';
} else {
window.location = '/Home/PurchaseFail';
}
}, function () {
alert('error');
});
Here is the method on my MVC controller.
public ActionResult PlaceOrder(PlaceOrderViewModel viewModel)
{
}
It accepts a view model from the Angular post request, and does some work. Then I have it returning either the purchase success or purchase fail view with the order model attached to a successful order.
return View("~/Views/Home/PurchaseSuccess.cshtml", order);
return View("~/Views/Home/PurchaseFail.cshtml");
Returning the view does not work. MVC does not seem to be able to handle the change in views since the request was made from Angular? The redirect in the Angular success handler is already working, and works great when you do not have a model being returned.
I basically just need to be able to redirect to the purchase success view with the model.
Thank you for your time!
EDIT: Here is the purchase success and purchase fail controller methods:
public ActionResult PurchaseSuccess()
{
return View();
}
public ActionResult PurchaseFail()
{
return View();
}