Quantcast
Channel: ActiveTopics
Viewing all articles
Browse latest Browse all 72689

BeginUmbracoForm changes route value

$
0
0

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


Viewing all articles
Browse latest Browse all 72689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>