Craig100
08/05/2023, 2:49 PM@using (Html.BeginUmbracoForm<MyFormSurfaceController>(nameof(MyFormSurfaceController.Submit))) {
....theForm....
}
It's on page called "test". However, when I look at the HTML produced it's just:
<form action="/test/" enctype="multipart/form-data" id="form796f5d50fb3440b4b4c611bbe6f4e54d" method="post">
and never hits the Surface Controller, for obvious reasons.
However, if I use @using (Html.BeginForm("Submit", "MyFormSurface", FormMethod.Post)) {
...theForm...
}
The HTML is:
<form action="/umbraco/surface/myformsurface/Submit" method="post">
And the Surface Controller is hit.
So what's wrong with BeginUmbracoForm or shouldn't it be used in a ViewComponent?
2)
However, if the model is invalid I then return CurrentUmbracoPage()
and I get the error:
InvalidOperationException: Can only use UmbracoPageResult in the context of an Http POST when using a SurfaceController form
What should I do to return to the form page?
Thanks.huwred
08/05/2023, 3:23 PMCraig100
08/05/2023, 3:26 PMCraig100
08/05/2023, 3:27 PMreturn RedirectToCurrentUmbracoPage()
then I get:-
InvalidOperationException: No UmbracoRouteValues feature was found in the HttpContext
Craig100
08/05/2023, 3:29 PMhuwred
08/05/2023, 3:30 PMCraig100
08/05/2023, 3:31 PMSebastiaan
08/07/2023, 7:27 AMCraig100
08/07/2023, 8:48 AMSebastiaan
08/07/2023, 9:26 AMJason
08/08/2023, 3:06 PMBeginUmbracoForm
post back to the current page and are routed internally.
Following the example from the docs, on a fresh site, renders this for me (it's on my homepage)
html
<form action="/" enctype="multipart/form-data" id="form2e825402a9af4a058dca5849724c4b25" method="post">
...
</form>
But my surface controller gets hit just fineJason
08/08/2023, 3:09 PMJason
08/08/2023, 3:11 PMCraig100
08/09/2023, 3:15 PMCraig100
08/12/2023, 12:52 PMJason
08/12/2023, 1:18 PMCraig100
08/12/2023, 1:19 PMCraig100
08/13/2023, 3:36 PMJason
08/13/2023, 3:40 PMCraig100
08/13/2023, 4:04 PMhuwred
08/14/2023, 7:30 AMcsharp
@using (Html.BeginUmbracoForm<MembershipSurfaceController>("SubmitSigninForm", null, new { id = "submitsigninform", @action = "/" }))
{
}
controller method
csharp
[HttpPost]
[ValidateUmbracoFormRouteString]
[IgnoreAntiforgeryToken]
public IActionResult SubmitSigninForm(PortalSigninViewModel model)
{
...
}
huwred
08/14/2023, 7:35 AMcs
@{
Layout = "_LayoutBody.cshtml";
var redirect = TempData["Redirect"];
var result = TempData["FormResult"];
}
@await Html.CachedPartialAsync("Layout/_pageBanner", Model, TimeSpan.FromHours(1),true)
<section our-if="@result != null">
<div class="container text-center " >
@result
</div>
</section>
<section our-if="@result == null">
<div class="container">
<div class="row">
<div class="col-6 offset-3">
@(await Component.InvokeAsync("Membership", new { viewname = "Signin" }))
</div>
</div>
</div>
</section>
<script type="text/javascript" our-if="@redirect != null">
setTimeout(() => {
location.href = "@redirect";
}, 500);
</script>
Craig100
08/14/2023, 10:23 AMhuwred
08/14/2023, 10:37 AMCraig100
08/14/2023, 10:37 AMCraig100
08/14/2023, 10:38 AMhuwred
08/14/2023, 11:21 AMhuwred
08/14/2023, 11:23 AM@using (Html.BeginUmbracoForm<PortalProfileSurfaceController>("SubmitForm", null, new { }, FormMethod.Post))
This is the controller method
cs
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult SubmitForm(ProfileModel model)
{
if (ModelState.IsValid)
{
var currentUser = _membermanager.GetCurrentMemberAsync().Result;
var member = _memberservice.GetByUsername(currentUser.UserName);
member.SetValue("firstname", model.Firstname);
member.SetValue("lastname", model.Lastname);
member.Email = (model).Email;
member.SetValue("mobile", (model).Mobile);
_memberservice.Save(member);
if (!string.IsNullOrEmpty(model.Password) && model.Password == model.ConfirmPassword)
{
var token = _membermanager.GeneratePasswordResetTokenAsync(currentUser).Result;
_membermanager.ChangePasswordWithResetAsync(member.Id.ToString(), token, model.Password);
_memberservice.Save(member);
}
new Contacts( _httpContext,_crmWebClient,_sess).Update( model.Firstname, model.Lastname, model.Email, model.Mobile);
return RedirectToCurrentUmbracoPage();
}
return CurrentUmbracoPage();
}
Craig100
08/14/2023, 12:39 PM