Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • jake williamson 207 posts 873 karma points
    Jul 09, 2015 @ 08:25
    jake williamson
    0

    how to use 'RedirectToAction' in a controller that inherits from 'RenderMvcController'?

    hey out there,

    hit a weird one: we've a site where each doctype has it's own controller. each controller inherits from 'RenderMvcController'.

    i'm trying to call 'RedirectToAction' to move from one controller to another and it's failing with a 'No route in the route table matches the supplied values.' ysod.

    this is the set up for controller one:

    public class BasketController : RenderMvcController
    {
        [HttpGet]
        public ActionResult Index(BasketViewModel model)
        {
            var viewModel = ViewModelFactory.Create<BasketViewModel>(model.Content);
    
            return CurrentTemplate(viewModel);
        }
    }
    

    and this is controller two, the one were i'm trying to redirect back to controller one:

    public class CheckoutController : RenderMvcController
    {
        [HttpGet]
        public ActionResult Index(BasketViewModel model)
        {
            var viewModel = ViewModelFactory.Create<CheckoutViewModel>(model.Content);
    
            if (viewModel.Basket.TotalItemQuantity == 0) return RedirectToAction("Index", "Basket", new {area = ""});
    
            return CurrentTemplate(viewModel);
        }
    }
    

    i've seen a couple of suggestions online to do 'return Redirect("~/basket");' which seems clunky and i'm not a big fan of the url being hardcoded?

    is 'RedirectToAction' possible in the way i'm trying?

    any suggestions would be grand!

    cheers,

    jake

  • Carl Jackson 139 posts 478 karma points
    Jul 09, 2015 @ 12:41
    Carl Jackson
    1

    AFAIK umbraco uses its own routing which will break the route table for RedirectToAction().

    It is maybe that there is no catch all {controller}/{action} route? but I'm not familiar with the core...

    This article seems to have info aboput registering routes without breaking the Umbraco routing. http://shazwazza.com/post/custom-mvc-routes-within-the-umbraco-pipeline/

    Or - if the checkout page exists in Umbraco can you not do something like

    var checkoutPage = Umbraco.Content(123); //checkout page id here
    
    return Redirect(checkoutPage.Url);
    

    Thanks

    Carl

Please Sign in or register to post replies

Write your reply to:

Draft