Copied to clipboard

Flag this post as spam?

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

  • David Dimmer 76 posts 134 karma points
    Jan 03, 2014 @ 02:47
    David Dimmer

    Integrating a Contact Form With Custom (surface) Controller


    We are trying to get our contact form working, with an MVC SurfaceController. Everything renders out correctly, but we are unable to get the form to post back on a submit. Code below. The controller and the model are i nthe App_Code folder.



    public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController



        public ActionResult ContactForm()


            return PartialView("Contact", new ContactModel());




        public string ContactForm(ContactModel contact)


    //Do Stuff Here

            return "Success";





    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage


        Layout = "Master.cshtml";


    <div id="content" class="textpage">



    <div class="full_blue_box" style="min-height: 350px;">

    <div style="width: 250px; float: left; padding-right: 25px; border-right: 1px solid #fcfcfc;">

    <h2><span style="color: #ffffff;">Get in Touch</span></h2>

    @*@Umbraco.RenderMacro("ContactForm", new { Subject = "Subject Parameter", YourEmail="[email protected]" })*@    

                          @Html.Partial("_ContactForm", new ContactModel())                                


    <div style="width: 520px; float: right; padding-left: 25px;">

    <h3><span style="color: #ffffff;">Office address</span></h3>







    @model ContactModel


    @using (Html.BeginUmbracoForm<ContactSurfaceController>("ContactForm"))



        <legend>Your details</legend>

        <form id="contactForm">


            @Html.TextBoxFor(model => model.Subject, new { placeholder = "Subject" })

            @Html.ValidationMessageFor(model => model.Subject)



             @Html.TextBoxFor(model => model.Email, new { placeholder = "Email Address" })

            @Html.ValidationMessageFor(model => model.Email)


           @Html.TextAreaFor(model => model.Message, new { placeholder = "Your Message" })

            @Html.ValidationMessageFor(model => model.Message)


            <input type="submit" value="Send Email"/>






    public class ContactModel


        public string Subject { get; set; }

        public string Email { get; set; }

        public string Message { get; set; }


  • Andy Butland 400 posts 2256 karma points MVP 4x hq c-trib
    Jan 03, 2014 @ 11:27
    Andy Butland

    It might be because you have both the GET and POST action methods named the same.  This allowed in MVC (and C# of course) due to the method overloading, but Umbraco can get confused with this.  There's an attribute [NotChildAction] you can add to the POST method.  And for completeness, you should also really add [ChildActionOnly] to the GET.

    See here for details.

    Hope that helps.


  • David Dimmer 76 posts 134 karma points
    Jan 07, 2014 @ 23:32
    David Dimmer

    Thanks - this definitely got us going the right direction. We will post our solution in the future. -David

  • Nick 101 posts 123 karma points
    May 22, 2014 @ 13:32

    So did you get it working and can you post your solution?



Please Sign in or register to post replies

Write your reply to: