ifury98
11/14/2023, 10:39 PMifury98
11/15/2023, 9:40 AMkdx-perbol
11/15/2023, 10:05 AMBeginUmbracoForm request with your AJAX request. Sounds like the path, querystring or POST data is wrong/insufficient.
But in 9+ you need to register your Umbraco routes in a way you didn't need to in 7/8. If you look into the documentation on registering surface controller routes it could be there.Sebastiaan
11/15/2023, 10:23 AMifury98
11/15/2023, 4:12 PMkdx-perbol
11/15/2023, 9:55 PM/umbraco/surface/{controllername}/{action}/{id}kdx-perbol
11/15/2023, 9:57 PMBeginUmbracoForm etc if you are posting (from HTML) to the surface controller.ifury98
11/15/2023, 10:12 PMifury98
11/15/2023, 10:14 PMkdx-perbol
11/16/2023, 7:41 AMBeginUmbracoForm . Unless there is a BeginUmbracoAjaxForm, you probably have to pass a page ID in the form ("current page ID"), and use UmbracoContext in the controller, but not CurrentPage. So sort of "brew your own" BeginUmbracoForm but for AJAX. (Didn't know people still said AJAX 🙂 )huwred
11/16/2023, 9:44 AMjs
$(document).on("click","#signin-btn", function (e) {
e.preventDefault();
e.stopPropagation();
var form = $("#submitsigninform");
$.ajax({
url: "/umbraco/surface/membershipsurface/submitsigninform",
type: "POST",
data: form.serialize(),
beforeSend: function (xhr) {
xhr.setRequestHeader("RequestVerificationToken",
$('#submitsigninform input:hidden[name="__RequestVerificationToken"]').val());
},
error: function (xhr, status, error) {
console.log(xhr.responseText);
}
});
});
In your surface controller your method should look like
cs
[HttpPost]
[ValidateUmbracoFormRouteString]
[IgnoreAntiforgeryToken]
public IActionResult SubmitSigninPage( PortalSigninViewModel model)
{
var test = UmbracoContext.PublishedRequest.PublishedContent;
if (ModelState.IsValid)
{
...
//something was wrong so add an error
ModelState.AddModelError("SigninError", result);
return CurrentUmbracoPage();
}
return CurrentUmbracoPage();
}ifury98
11/17/2023, 3:52 PM