Search code examples
umbracoumbraco7surface-controller

Umbraco surface controller not submitting to backend with POST


I basically have a contact form, which I need to POST to my Umbraco backend. The frontend looks similar to this:

using (Html.BeginUmbracoForm("HandleFormSubmit", "ContactForm", FormMethod.Post)) {
    <form>
        <input name="Name" type="text" />
        <button type="submit">Send</button>
    </form>
}

I then have a surface controller in /Controllers/ContactFormController.cs that looks like:

public class ContactFormController : SurfaceController {
    // GET: ContactForm
    public ActionResult Index() {
        return PartialView("ContactForm", new ContactForm());
    }

    [HttpPost]
    public ActionResult HandleFormSubmit(ContactForm model) {
        return RedirectToCurrentUmbracoPage();
    }
}

I am trying to hit the HandleFormSubmit POST method. The GET method works (breakpoint proves that). No matter what I do, I cannot get it to hit this method. I've looked at tons of guides and all of them seem to be the exact same as this.

The POST data is as follows:

url: /contact-us/
data: name="Test"
Content-Type: multipart/form-data

What am I doing wrong here? Using Umbraco 7.6.6


Solution

  • Your problem is that you are rendering form inside the form.

    Your view should look like this:

    using (Html.BeginUmbracoForm("HandleFormSubmit", "ContactForm", FormMethod.Post)) {
        <input name="Name" type="text" />
        <button type="submit">Send</button>
    }
    

    And it should work.