Copied to clipboard

Flag this post as spam?

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


  • Moran 277 posts 885 karma points
    Nov 16, 2013 @ 19:45
    Moran
    0

    handle post in surface controller

    I am trying to create a surface controller using this video but for some reason it won't handle my posts. this is my controller code:

    public class ContactFormController : SurfaceController { // // GET: /ContactForm/

        public ActionResult Index()
        {
            return PartialView("ContactForm", new ContactFormViewModel());
        }
    
        [HttpPost]
        public ActionResult FormSubmit(ContactFormViewModel model)
        {
            return RedirectToCurrentUmbracoPage();
        }
    }
    

    this is my cshtml code:

    @using (Html.BeginUmbracoForm<SurfaceControllersSample.Controllers.ContactFormController>("FormSubmit"))
    {
        <div>
            @Html.TextBoxFor(m => m.Name, new { placeholder = "Name" })
        </div>
        <div>
            @Html.TextBoxFor(m => m.Email, new { placeholder = "Email" })
        </div>
        <div>
            @Html.TextAreaFor(m => m.Message, new { placeholder = "Message" })
        </div>
        <div>
            <button id="submit">Send</button>
        </div>
    }
    

    it will go to the "Index" method but not the "FormSumbit" Method. Any ideas?

  • Ali Sheikh Taheri 470 posts 1647 karma points c-trib
    Nov 17, 2013 @ 00:32
    Ali Sheikh Taheri
    0

    Hi Moran,

    I believe you should change your class name from ContactFormController to ContactFormSurfaceController and also in your cshtml file

    @using (Html.BeginUmbracoForm<SurfaceControllersSample.Controllers.ContactFormSurfaceController>("FormSubmit"))
    

    hope that helps.

    Cheers

    Ali

  • Moran 277 posts 885 karma points
    Nov 17, 2013 @ 07:00
    Moran
    0

    Hi Thanks, I named it something else and forgot to attach the code for the most important thing, my controller :) here it is:

    public class ContactFormController : SurfaceController
    {
        //
        // GET: /ContactForm/
    
        public ActionResult Index()
        {
            return PartialView("ContactForm", new ContactFormViewModel());
        }
    
        [HttpPost]
        public ActionResult FormSubmit(ContactFormViewModel model)
        {
            return RedirectToCurrentUmbracoPage();
        }
    }
    

    Even if I tried to insert a breaking point in the FormSubmit, But it won't get there.

  • Moran 277 posts 885 karma points
    Nov 19, 2013 @ 18:27
    Moran
    0

    Any thoughts?

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Nov 19, 2013 @ 18:37
    Tim Geyssens
    0

    Seems good :) but make sure you are running in MVC mode and the template you are outputting the form on is a razor view and not a .net masterpage

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Nov 19, 2013 @ 18:38
    Tim Geyssens
    100

    And make sure you don't have nested forms...

  • Ali Sheikh Taheri 470 posts 1647 karma points c-trib
    Nov 19, 2013 @ 18:46
    Ali Sheikh Taheri
    0

    Hi Moran,

    The controller's name must be suffixed with the term 'SurfaceController' based on this page:

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Nov 19, 2013 @ 19:29
    Tim Geyssens
    0

    @Ali Don't think that's mandatory...

  • Moran 277 posts 885 karma points
    Nov 19, 2013 @ 19:38
    Moran
    0

    Ok So I just need to rename my 'ContactFormController' to 'ContactFormSurfaceController'? I did that and updated my code accordingly but still no post :( this is my code in the master page maybe I need to call the FormSumbit method also

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    <h1>@CurrentPage.Name</h1>
    @Html.Action("Index", "ContactFormSurface")
    
  • Moran 277 posts 885 karma points
    Nov 19, 2013 @ 19:41
    Moran
    0

    Thanks Tim My bad I had a form tag in the master page, old habits die hard :) Thanks everyone :)

    P.S Great work with the videos Tim :)

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Nov 19, 2013 @ 20:36
    Tim Geyssens
    0

    @Moran thanks :) and glad I could help

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies