Copied to clipboard

Flag this post as spam?

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


  • Jon 67 posts 141 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 90 posts 688 karma points
    Feb 18, 2021 @ 15:54
    Joep
    0

    Hi Jon,

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

    -Joep

  • Jon 67 posts 141 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 335 posts 1007 karma points
    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 67 posts 141 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 335 posts 1007 karma points
    Feb 18, 2021 @ 20:44
    Huw Reddick
    0

    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 335 posts 1007 karma points
    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

  • 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