Copied to clipboard

Flag this post as spam?

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


  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 23, 2017 @ 21:31
    Sören Deger
    0

    Html.BeginnUmbracoForm not call SurfaceController Action

    Hi Umbracians,

    I have the following problem: If I call my Surface Action directly per URL in Browser the action is found:

    http://localhost:55759/umbraco/surface/contactForm/submit

    But my contact form by using Html.BeginnUmbracoForm don't call this action. I don't know why I can call the action from url, but why the partial view not call this action If I click on the submit button.

    Model:

    namespace UmbracoWebsite.Logic
    {
        public class ContactFormModel
        {
                [Required]
                public string Name { get; set; }
                [Required]
                [EmailAddress]
                public string Email { get; set; }
                [Required]
                public string Betreff { get; set; }
                [Required]
                public string Mitteilung { get; set; }
        }
    }
    

    Controller:

    namespace UmbracoWebsite.Logic
    {
        public class ContactFormController : SurfaceController
        {
            [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
            [ValidateAntiForgeryToken]
            [ChildActionOnly]
            public ActionResult Submit(ContactFormModel model)
            {
                if (model.Name == "Sören")
                {
                    return Content("True", "application/json");
                } else
                {
                    return Content("False", "application/json");
                }
            }
        }
    }
    

    PartialView:

    @model UmbracoWebsite.Logic.ContactFormModel
    
    @{
    
        using (Html.BeginUmbracoForm("Submit", "ContactForm", FormMethod.Post, new { name = "ContactForm", id = "KontaktForm" }))
        {
            @Html.AntiForgeryToken()
            <form class="form-horizontal">
                <div class="form-group">
                    @Html.LabelFor(x => x.Name)
                    @Html.TextBoxFor(x => x.Name, new { @class = "form-control", @required="required" })
                    @Html.ValidationMessageFor(m => m.Name)
                </div>
                <div class="form-group">
                    @Html.LabelFor(x => x.Email)
                    @Html.TextBoxFor(x => x.Email, new { @type = "email", @class = "form-control", @required = "required" })
                    @Html.ValidationMessageFor(m => m.Email)
                </div>
                <div class="form-group">
                    @Html.LabelFor(x => x.Betreff)
                    @Html.TextBoxFor(x => x.Betreff, new { @class = "form-control", @required = "required" })
                    @Html.ValidationMessageFor(m => m.Betreff)
                </div>
                <div class="form-group">
                    @Html.LabelFor(x => x.Mitteilung)
                    @Html.TextAreaFor(x => x.Mitteilung, new { @class = "form-control", @rows = "8", @required = "required" })
                    @Html.ValidationMessageFor(m => m.Mitteilung)
                </div>
                <div class="form-group">
                    <input type="submit" id="submit" name="Kontakt" class="btn btn-default" value="Senden" />
                </div>
            </form>
        }
    }
    

    I'm using Umbraco v7.7.7.

    Have anyone an idea to solve this?

    Best, Sören

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Dec 23, 2017 @ 23:42
    Anders Bjerner
    100

    Hi Sören,

    Html.BeginUmbracoForm will automatically generate the <form> element, so since you've also added your own <form> element, it prevents the form from submitting correctly.

    If you remove your own <form> element, the form is successfully submitted to the controller ;)

  • Sören Deger 733 posts 2844 karma points c-trib
    Dec 24, 2017 @ 07:15
    Sören Deger
    0

    Hi Anders,

    of course, this works! It was too late last evenig ;-) Thank you and I wish you a merry christmas.

    Best, Sören

Please Sign in or register to post replies

Write your reply to:

Draft