0

Is it possible to post data from a form with controller rendering on page1 to a controller rendering on page2?

I mean the form submit on page1 should post back with page2 as page context.

Update 1: tried below option of adding scItemPath in route.. no luck

https://jockstothecore.com/to-the-controller-and-back-part-1-routing/

scItemPath passed in routevalues is appending to route like controller/action/{scItemPath}, but not invoking the pagecontext of item id passed.

Update 2: adding code

view (rendered using conroller rendering on item1)

@using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, new { scItemPath = "path/to/item2"}, FormMethod.Post, new { @name = "selectLoginCredentialsForm", @class = "adjacent_error_wrap", @enctype = "multipart/form-data" }))
    {
        @Html.AntiForgeryToken()
        @Html.Sitecore().FormHandler("RegistrationSecurity", "SetSecurityDetails")
//form inputs
<input name="username" type=text/>
<input name="password" type=text/>
<input type="submit" value="submit"/>
}

Controller

 public class RegistrationSecurityController : GlassController
{

    public ActionResult SetSecurityDetails(UserCredentials creds)
    {
        var model = GetDataSourceItem<Idatasource>();
        return View("~/Views/path/to/view.cshtml", model);
    }
}
  • you can call $.ajax method on button click. on success set window.location.href. you can keep form data into session. – Abhishek Malaviya Aug 27 '19 at 6:25
  • @AbhishekMalaviya - thought of this solution, but do not want to use session for storing and retrieving sensitive information. – nari447 Aug 27 '19 at 7:55
0

You may invoke child ajax method on success and pass login form data to this ajax method. Here child ajax method will call another page controller action method.

$('#btnSubmit').click(function (e) {
        var formdata = $("#frmLogin").serialize();
        $.ajax({
            url: $("#frmLogin").attr('action'),
            type: "POST",
            data: formdata,
            success: function (result) {
                if (result.Success == "Success") {
                    // Now call another ajax method to pass data
                     $.ajax({
                     url: //pass another page controller action,
                     type: "POST",
                     data: formdata,
                     success: function (result) { }                
                     });
            },
            error: function (Error) {

            }

        });
    });

Hopefully this will help you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.