logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Joe Payne2  
#1 Posted : Friday, January 29, 2021 10:04:43 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
I am struggling to figure out how to redirect the user to a different page from within a controller.

I created a partial view with the RegisterWidget[] decorator in the controller so the CMS will pick it up.

I build a new inner template and add my widget. Then I set up a content page and assign to my inner template.

All of this works great. The url renders, my GET method fires and I populate the model. Page works exactly like I need it.

The problem starts when I set up a form that does a POST back to the controller. I need to pull in my page model properties, populate the class object and save. That all works.

At the end of the postback, I want to redirect the user to a different place. For example, the home page. I can't figure out how to redirect at the end of the POST method.

I've tried copying examples I've found elsewhere in Able, nothing works. All it does is render the actual javascript instead of executing it.

Here's my form:

Code:


                @using (Html.BeginForm("Proceed", "RegisterInvitee", FormMethod.Post))
                {
                    @Html.AntiForgeryToken()
                    <p>
                        As a non-US Citizen, no further details are required.
                    </p>
                    @Html.HiddenFor(model => model.Email)
                    <input type='Submit' value='Proceed To Welcome Page' class="btn btn-primary" />
                }



Here's the method:
Code:

        [AllowAnonymous]
        [HttpPost]
        [ValidateAntiForgeryToken]
        public JavaScriptResult Proceed(RegisterInviteeModel model)
        {
            // pull up user specified in model
            User u = _userRepo.LoadForUserName(model.Email);
            if (u != null)
            {
                // user object exists, update address profile
                Address address = u.PrimaryAddress;

                // set address flag based on citizenship
                address.Residence = false;
                _addressRepo.Save(address);

                // authenticate this user account into Able
                FormsAuthentication.SetAuthCookie(model.Email, false);
            }

            // we're done, dump user to home page
            //return PartialView("_RegisterInvitee", model);
            return JavaScript(string.Format(" window.location = '{0}' ", Url.Content("~/")));
        }


Here is all I see when the method ends with the redirect

Capture.JPG (17kb) downloaded 0 time(s).

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

Joe Payne2  
#2 Posted : Friday, January 29, 2021 1:11:27 PM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Apparently this works when using ActionResult as the return type. Mucho thank you to Joy @ Web2Market for the help!

Code:

return RedirectToLocal("~/Account");
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.