Copied to clipboard

Flag this post as spam?

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

  • Richard Terris 273 posts 715 karma points
    Aug 20, 2014 @ 16:46
    Richard Terris

    Redirect to thank you page

    Hi all,

    Really hope someone can help.

    I have a website which has a contact form on every page which is hidden and shown with some jQuery.

    Posting the form and sending the email to the site email address is fine, but the trouble is coming as I want to redirect to a thank you page.

    I tried redirecting from the controller which handles the form submission and now I have created a ThankYouController which inherits SurfaceController

    I have tried various approaches to this, RedirectToAction, Redirect and not getting the result I want in any case. Depending on the approach I get issues with this.Umbraco.AssignedContentItem as it's not handled by Umbraco, or as is the case at the moment, the page I've redirected to seems to be being rendered as a partial view.

    Does anyone know the correct way to do this?

  • Paul Wright (suedeapple) 277 posts 704 karma points
    Aug 20, 2014 @ 16:56
    Paul Wright (suedeapple)

    Something as simple as...

    return Redirect(CurrentPage.Children.First().Url);
  • Richard Terris 273 posts 715 karma points
    Aug 20, 2014 @ 17:00
    Richard Terris

    Thanks Paul,

    but if I use Redirect("some url"); then I get redirected correctly but the page is being rendered like a partial, so at the top section where the form would be.

    If I use return View("view name"); then I get the page but lose the AssignedContentItem stuff which I need.

    The easiest thing would be to redirect to the current page return CurrentUmbracoPage(); but we need to redirect to a thank you page.

    There must be a nice way people are doing this - anything I'm trying, even though it's not working, feels quite 'hacky'

  • Andrew 3 posts 43 karma points
    Aug 20, 2014 @ 17:20

    I'd so something like this to get the thank you page,

    // Might be a bit tricky if you have more than one root node
    IPublishedContent root = Umbraco.TypedContentAtRoot().FirstOrDefault();
    // And assuming you only have one thank you page
    IPublishedContent thankYou = root.DescendantsOrSelf("ContactThankYou").FirstOrDefault();
    if (thankYou != null)
        return this.Redirect(thankYou.Url);

    After the redirect that should be a normal page loading through Umbraco, if you're getting a partial view, check you don't have

    Layout = null;

    in the view.

  • Richard Terris 273 posts 715 karma points
    Aug 20, 2014 @ 17:56
    Richard Terris


    Thanks to those who made suggestions.

    Looks like TempData["emailSuccess"] = emailSuccess; return Redirect("~/thank-you"); was working all along but some jQuery issues were rending the result in the header.

    I could have saved myself a couple of hours on this!

Please Sign in or register to post replies

Write your reply to: