Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Frans Lammers 57 posts 400 karma points c-trib
    Mar 24, 2020 @ 13:51
    Frans Lammers
    0

    Surface controller calls GET instead of POST in submit

    Hi,

    In a project I have a form on a partial view that gets rendered through a surface-controller. The form is made using Html.BeginUmbracoForm("action", "controller"). When I click on the submit button I expect to be led to the POST-method, but everytime I return to the GET-method instead.

    Here's the view that includes the partial:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ForgotPassword>
    
    @using Project.Core.Models
    
    @{
        Layout = "Master.cshtml";
    }
    
    
    <!-- Page Title-->
    <div class="page-title">
        <div class="container">
            <div class="column">
                <h1>Forgot password</h1>
            </div>
        </div>
    </div>
    <!-- Page Content-->
    <div class="container padding-bottom-3x mb-2">
        <div class="row">
            <div class="offset-md-3 col-md-6">
                @Html.Action("ForgotPasswordRenderForm", "ForgotPasswordSurface")
            </div>
        </div>
    </div>
    

    The partial looks like:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ForgotPasswordViewModel>
    
    @using Project.Core.Models
    
    @{
        using (Html.BeginUmbracoForm("ForgotPasswordPost", "ForgotPasswordSurface"))
        {
            @Html.AntiForgeryToken()
    
    
            <div class="container padding-bottom-3x mb-2">
                <div class="row justify-center">
                    <div class="col-lg-8 col-md-10">
                        <h2>Forgot your password?</h2>
                        <form class="card mt-4">
                            <div class="card-body">
                                <div class="form-group">
                                    @Html.LabelFor(m => m.Email)
                                    @Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
                                    @Html.ValidationMessageFor(m => m.Email)
                                </div>
                            </div>
                            <div class="card-footer">
                                <button class="btn btn-primary" type="submit">Get New Password</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
    
        }
    }
    

    And this is the Surfacecontroller:

      public class ForgotPasswordSurfaceController : SurfaceController {
    
            [ChildActionOnly]
            public ActionResult ForgotPasswordRenderForm()
            {
                ForgotPasswordViewModel model = new ForgotPasswordViewModel();
    
                return PartialView("Profile/Forgotpassword", model);
            }
    
    
            [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult ForgotPasswordPost(ForgotPasswordViewModel model)
            {
                if (ModelState.IsValid)
                {
                     // send mail to reset password
                    TempData["Status"] = "success";
                    TempData["StatusMessage"] = "A mail is send to this email address to reset the password";
                    return CurrentUmbracoPage();
                }
                return CurrentUmbracoPage();
            }
        }
    

    Can anyone see what I am doing wrong here?

    thanks,

    Frans

  • Joep 96 posts 698 karma points
    Mar 24, 2020 @ 15:24
    Joep
    0

    Hi,

    Have you tried adding a FormMethod to your form?

    using (Html.BeginUmbracoForm("ForgotPasswordPost", "ForgotPasswordSurface", FormMethod.Post)
    

    -Joep

  • Frans Lammers 57 posts 400 karma points c-trib
    Mar 24, 2020 @ 15:29
    Frans Lammers
    0

    Hi Joep,

    Yes, I have tried that. Unfortunately it made no difference.

    thanks,

    Frans

  • Nigel Wilson 944 posts 2076 karma points
    Mar 25, 2020 @ 00:36
    Nigel Wilson
    0

    Hi Frans

    How about trying the following:

    @using (Html.BeginUmbracoForm<ForgotPasswordSurfaceController>("ForgotPasswordPost", null, new { @class = "form" }))
    { ... }
    

    Cheers

    Nigel

  • Frans Lammers 57 posts 400 karma points c-trib
    Mar 25, 2020 @ 08:20
    Frans Lammers
    100

    Hi Nigel,

    Thanks, this didn't work either.

    But I found the problem: I was using a theme made by somebody else for this site and when reading into the Html closer I found a really hidden extra form tag. A form within a form doesn't work so removing that was the solution. (make a note to myself: read all the external code you use very close)

    cheers,

    Frans

Please Sign in or register to post replies

Write your reply to:

Draft