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
    0

    Integrating a Contact Form With Custom (surface) Controller

    All,

    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.

     

    CONTROLLER

    public class ContactSurfaceController : Umbraco.Web.Mvc.SurfaceController

    {

        [HttpGet]

        public ActionResult ContactForm()

        {

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

        }

     

        [HttpPost]

        public string ContactForm(ContactModel contact)

        {

    //Do Stuff Here

            return "Success";

        }

    }

     

    VIEW

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{

        Layout = "Master.cshtml";

    }

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

    <h3>@CurrentPage.Title</h3>

    <h4>@CurrentPage.subTitle</h4>

    <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>

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

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

    @Umbraco.Field("content")

    </div>

    </div>

    </div>   

     

    PARTIAL VIEW

    @model ContactModel

     

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

    {

    <fieldset>    

        <legend>Your details</legend>

        <form id="contactForm">

        <p>

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

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

        </p>

        <p>

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

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

        <p>

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

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

     

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

        </form>

    </fieldset>

    }

     

    CONTACTMODEL

    public class ContactModel

    {

        public string Subject { get; set; }

        public string Email { get; set; }

        public string Message { get; set; }

    }

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

    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.

    Andy

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

    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
    Nick
    0

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

     

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft