Redirecting to another page ..inside a [Non Action] procedure

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
There is a procedure that takes care of the Shopping Cart.

FILE >> Nop.Web.Controllers.ShoppingCartController
PROCEDURE >>        
[NonAction]
private ShoppingCartModel PrepareShoppingCartModel(ShoppingCartModel model,
            IList<ShoppingCartItem> cart, bool isEditable, bool setEstimateShippingDefaultAddress = true)


Right at the beginning, the procedure checks for cart.Count == 0.
If the cart is empty, it return the model to the page so that it can displays an empty page stating "Your Shopping Cart is empty!"

I would like to know what is the best way to redirect to another page, in case of the cart.Count == 0.
Any ideas will be very welcome !!
12 years ago
The only way of doing it is check whether a cart doesn't have any items in your action method ('Cart' method in your case) and return a RedirectToAction if required
12 years ago
By Action Method, are u referring to the [NonAction] procedure I stated above?
Cause if that the one, because of the return type, we cannot return a RedirectToAction.

Compiler will tell us NOPE.
What I did, so far, is this:

if (cart.Count == 0)
   Response.Redirect("/");
else
{
   ....
   ....
   ....
}

return model.

======================
...but i'm sure that is not the right way to do it :--)
12 years ago
By action method I meant 'Cart' method of 'ShoppingCartController'
P.S. Do not use  "Response.Redirect" in your controllers, use 'RedirectToAction' or 'RedirectToRoute' like it's done other mnethods
12 years ago
But that's my point,

The method that looks like
[NonAction]
private ShoppingCartModel PrepareShoppingCartModel(ShoppingCartModel model,
      IList<ShoppingCartItem> cart, bool isEditable, bool setEstimateShippingDefaultAddress = true)

If I try to return an RedirectToAction,
the compiler does not allow me that.

:--)
12 years ago
Please see my posts above. Place the required redirection logic into the 'Cart' method (not the  'PrepareShoppingCartModel' one)
12 years ago
Ok ..got it.

I also had to update the following Cart calls:

>> public ActionResult RemoveCart(FormCollection form)
>> public ActionResult UpdateCart(FormCollection form)

and your suggested
>> public ActionResult Cart()

Thanks !!!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.