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>
{
- I click the button to open the form
- The method Modal in my controller get hit and return my form as a partial view and displays it to the user.
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"
I click Save and ends up in Modal in CustomerListApi instead of SaveCustomer.
Any suggestions of where I'm wrong?
Thanks