MVC3 - Redirect from a [NonAction] Controller event?

Return type should be ActionResult and you should return View(model) instead of only model . Your code should be like below.

Up vote 0 down vote favorite share g+ share fb share tw.

NonAction private ShoppingCartModel PrepareShoppingCartModel(ShoppingCartModel model, IList cart) { if (cart == null) throw new ArgumentNullException("cart"); if (model == null) throw new ArgumentNullException("model"); if (cart. Count == 0) return model; ...bla bla bla (lots of code) } Now on the 3rd line, if the Cart. Count if = 0, instead of returning a empty model, that gets the View Display empty, I would rather redirect to the Home Page.

I cannot use return RedirectToAction() cause the compiler gives me the following error: Cannot implicitly convert type 'System.Web.Mvc. RedirectToRouteResult' to 'Web.Models.ShoppingCart. ShoppingCartModel' QUESTION: So what's the right way to exit a NonAction Controller procedure?

Asp. Net-mvc-3 link|improve this question asked Mar 12 at 7:39Developer3421414 58% accept rate.

Return type should be ActionResult and you should return View(model) instead of only model. Your code should be like below. NonAction private ActionResult PrepareShoppingCartModel(ShoppingCartModel model, IList cart) { if (cart == null) throw new ArgumentNullException("cart"); if (model == null) throw new ArgumentNullException("model"); if (cart.

Count == 0) return View(model); ...bla bla bla (lots of code) }.

Well, that code is already written and I cannot just change it. There is a reason for returning a type instead of a ActionResult. I'm in need to know how to redirect from here ...instead of changing the "here" :--) – Developer Mar 13 at 17:04.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions