Copied to clipboard

Flag this post as spam?

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


  • Anders 4 posts 75 karma points
    Mar 21, 2019 @ 09:27
    Anders
    1

    BeginUmbracoForm changes route value

    Hi

    I'm trying to redirect a partial view form post to a specific method in a controller. But it sees like Umbraco ignores my route and changes it to another route.

    The button on the main page triggering the modal:

    <button class="btn btn-primary" type="button" onclick="OpenCustomerForm()">New Customer</button>
    

    The script for this page:

    var urlApiController = '@Url.Action("Modal", "CustomerListApi")';
    
    function OpenPatientForm(customerId) {
        $.ajax({
            url: urlApiController,
            type: 'POST',
            data: {
                Id: customertId
            },
            success: function (value) {
                $("#addNewModal").html(value);
                showModal('#addNewModal');
            },
            error(e) {
                alert(e);
            }
        });
    }
    

    My controller:

     public class CustomerListApiController : SurfaceController
     {
         [HttpPost]
         public PartialViewResult Modal(int? Id)
         {
               //Do stuff
               return PartialView("Partials/Modals/_AddCustomer", myModel);
         }
    
        [HttpPost]
        public ActionResult SaveCustomer(Customer pCustomerModel)
        {
              //Do stuff
        }
    }
    

    My View:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<My Customer Model>
    
    @using (Html.BeginUmbracoForm("SaveCustomer", "CustomerListApi", FormMethod.Post, new { @enctype = "multipart/form-data", @id ="customerForm", @class = "needs-validation", @novalidate = "novalidate" }))
     {
         @* Input fields*@
         <div><button type="submit" class="btn btn-success" id="btnSave">Save</button></div>
     {
    
    1. I click the button to open the form
    2. The method Modal in my controller get hit and return my form as a partial view and displays it to the user.
    3. When I inspect the html rendered for the form I expected the route for the form to be something like "CustomerListApi/SaveCustomer" as I thought that this was the route that I set in Html.BeginUmbracoForm. But the html is: action="/umbraco/Surface/CustomerListApi/Modal"

    4. I click Save and ends up in Modal in CustomerListApi instead of SaveCustomer.

    Any suggestions of where I'm wrong?

    Thanks

  • Damien Holley 126 posts 425 karma points
    Dec 05, 2019 @ 00:59
    Damien Holley
    0

    +1 to this, the most I have heard about this problem is that there is something up with the routes when you use AJAX/JQ to get a partial view that causes all of the umbracoform routes to go wrong.

    I have yet to figure out an answer.

  • 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