Copied to clipboard

Flag this post as spam?

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


  • Jon 92 posts 166 karma points
    Feb 18, 2021 @ 15:51
    Jon
    0

    Redirect from Surface Controller to different URL

    Hi,

    Is it possible to redirect to a different url - for example a Thank you page from a surface controller. Im using the following but the Thank you page is inside the Original page - I need it to redirect to a new URL.

    I have used the following:

     [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitPersonalDetailsForm(PersonalDetails model)
        {
    
    return new RedirectResult(ViewDelegateURL, true);
    return this.RedirectToUmbracoPage(ViewDelegateId);
    

    Any ideas what I need to do to get this working?

  • Joep 96 posts 698 karma points
    Feb 18, 2021 @ 15:54
    Joep
    0

    Hi Jon,

    Can't you just use return Redirect(ViewDelegateURL);?

    -Joep

  • Jon 92 posts 166 karma points
    Feb 18, 2021 @ 15:59
    Jon
    0

    I must be doing something wrong - it doesnt actually redirect - but puts the new page inside the old page

  • Huw Reddick 1926 posts 6674 karma points MVP 2x c-trib
    Feb 18, 2021 @ 16:25
    Huw Reddick
    0

    you should definitely just be able to do

    return Redirect("/some-url");

    or

    return RedirectToUmbracoPage(umbracoPageId);

  • Jon 92 posts 166 karma points
    Feb 18, 2021 @ 17:18
    Jon
    0

    Would this stop it from working?

    My Front end partial form is using this:

    @using (Ajax.BeginForm("SubmitPersonalDetailsForm", "PersonalDetailsSurface", new AjaxOptions() {

  • Huw Reddick 1926 posts 6674 karma points MVP 2x c-trib
    Feb 18, 2021 @ 20:44
    Huw Reddick
    1

    In your controller, return JSON

    return Json(new { url = yoururl });

    Add an onsuccess function and assign it in your ajaxform options.

    var onSuccess = function(result) {
    if (result.url) {
        // if the server returned a JSON object containing an url 
        // property we redirect the browser to that url
        window.location.href = result.url;
    }
    

    }

  • Huw Reddick 1926 posts 6674 karma points MVP 2x c-trib
    Feb 18, 2021 @ 17:46
    Huw Reddick
    0

    Yes, you can't redirect from an Ajax post, you need to return the URL and redirect in the onsuccess function

Please Sign in or register to post replies

Write your reply to:

Draft