so simply my app cannot find the controller and the action.
btw it's not the problem of parameter as I removed parameters and just tried to call pure action and still couldn't find it.
I even converted the form to BeginUmbracoForm and still couldn't find my custom controller
Form:
@helper Modal()
{
var wvp = PageContext.Page as System.Web.Mvc.WebViewPage;
var Html = wvp.Html;
var Ajax = wvp.Ajax;
<form id="bookingForm" name="bookingForm" class="modal-form">
<fieldset>
<label for="Name">Name</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email</label>
<input type="text" name="Email" id="Email"" />
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</form>
}
Ajax:
function book() {
var url = "/Booking/Book";
var data = JSON.stringify({ model: $('#bookingForm').serialize()});
$.ajax({
contentType: 'json',
method: "POST",
url: url,
data: data,
success: alert("success"),
dataType: "html"
});
}
Controller:
public class BookingController : SurfaceController
{
[HttpPost]
public ActionResult Book(BookingModel model)
{
return this.View();
}
}
Controller not found when posting form via ajax
I have a form which I'm trying to send via ajax to a custom controller.
Form is rendered in a helper (in App_Code) and helper is called in one of my views.
Controller is under Controllers folder.
The problem is that I always get:
so simply my app cannot find the controller and the action. btw it's not the problem of parameter as I removed parameters and just tried to call pure action and still couldn't find it.
I even converted the form to BeginUmbracoForm and still couldn't find my custom controller
Form:
Ajax:
Controller:
What am I missing?
Hi,
As you have inherited your controller with SurfaceController so your url will be
http://localhost:49844/Umbraco/Surface/Booking/Book/
I hope this will help you!
Yasir
I tried it already and it didn't work. Still doesn't work with /Umbraco/Surface
Can you please make a get method in your controller and see is it working with umbraco/surface?
i am afraid that your json request is not sending the same parameter as expected.
Ok, I made it working. Thanks for hints!
is working on a reply...