Copied to clipboard

Flag this post as spam?

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


  • Moran 285 posts 934 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 1648 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 285 posts 934 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 285 posts 934 karma points
    Nov 19, 2013 @ 18:27
    Moran
    0

    Any thoughts?

  • Comment author was deleted

    Nov 19, 2013 @ 18:37

    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

  • Comment author was deleted

    Nov 19, 2013 @ 18:38

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

  • Ali Sheikh Taheri 470 posts 1648 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:

  • Comment author was deleted

    Nov 19, 2013 @ 19:29

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

  • Moran 285 posts 934 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 285 posts 934 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 :)

  • Comment author was deleted

    Nov 19, 2013 @ 20:36

    @Moran thanks :) and glad I could help

Please Sign in or register to post replies

Write your reply to:

Draft