Copied to clipboard

Flag this post as spam?

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


  • Bo Jacobsen 438 posts 1818 karma points
    Mar 16, 2017 @ 15:05
    Bo Jacobsen
    0

    Hijack umbraco route controller and redirect

    Using Umbraco 7.5.11

    I want to redirect or return another template after hijacking.

    This is what i got. it only return the same template.

    public class TestDocumentController : Umbraco.Web.Mvc.RenderMvcController
        {
            public override ActionResult Index(RenderModel model)
            {
                var home = model.Content.Site();
                model = new RenderModel(home);
    
                var firstChildDocument = model.Content.Children.FirstOrDefault();
                if (firstChildDocument != null)
                {
                    model = new RenderModel(firstChildDocument);
                }
    
                return View(model);
            }
        }
    

    Any idears?

  • Marc Goodson 1451 posts 9716 karma points MVP 5x c-trib
    Mar 16, 2017 @ 19:54
    Marc Goodson
    101

    Hi Bo

    I'm not overly sure what you are trying to achieve, but you could...

    return a RedirectToUmbracoPageResult (that takes the id of the page you want to redirect to)

    eg:

    return new RedirectToUmbracoPageResult(firstChildDocument.Id);
    

    or because this is MVC, you can return the name of any view or path to it followed by the relevant model like so:

     return View("~/Views/BlogPost.cshtml", model);
    

    regards

    Marc

  • Bo Jacobsen 438 posts 1818 karma points
    Mar 17, 2017 @ 07:33
    Bo Jacobsen
    0

    return new RedirectToUmbracoPageResult(int pageId); is exactly what i needed. Thanks.

    What i tried to achieve is to redirect to the first child 'if exist' of TestDocument. Since TestDocument does not have a template and is only a "Folder". Then fallback would be to return to the frontpage.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies