Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 445 posts 1059 karma points
    May 24, 2013 @ 12:20
    Ayo Adesina
    0

    How to handle form post Umbraco 6 - MVC

    Currently I have one page to my umbraco site with one Document type called 'HomePage'

    I have added a custom controller which returns my home page veiw, that works fine.
     
    From that same view I am trying to post the data from a form, I have created an action in the same controller to to handle the post called 'Contact'

    I have given it the attibuite [HttpPost] but when I submit the form I am not able to hit that controller I just get 'Page not Found', this is my code:

        public class HomePageController : RenderMvcController
         {
           public override ActionResult Index(RenderModel model)
           {  
               return View("HomePage");
            }  

            [HttpPost]
            public ActionResult Contact(FormCollection c)
    {
    //I WANT TO PROCESS MY FORM DATA HERE
            }

    <form id="contact-form" action="HomePage/Contact" method="post">

    <input id="name" class="rounded" name="contact[name]" type="text" />

    <input id="email" class="rounded" name="contact[email]" type="text" />

    <input id="submit-mail" class="submit-btn rounded" type="submit" value="SEND MESSAGE" />

     

    </form>

    I found this post: http://www.systenics.com/blog/creating-an-ajax-enabled-contact-form-in-umbraco-6-with-aspnet-mvc-4-and-twitter-bootstrap/?tag=Umbraco+6

    Which talks about haddling a form post, but it involes making a new document type to represent the form, and it gos on... but what I want to know is......... Is it really necessary to do this? Surely there must be a simple way just to post the back to the controller that renders it..?

    Any ideas?

     

  • Ayo Adesina 445 posts 1059 karma points
    May 25, 2013 @ 15:48
    Ayo Adesina
    0

    No replies :-(

  • Charles Afford 1163 posts 1709 karma points
    May 25, 2013 @ 19:22
    Charles Afford
    0

    hi i can help :)

  • Charles Afford 1163 posts 1709 karma points
    May 25, 2013 @ 19:42
    Charles Afford
    0

    hi i can help :)  Take a look at this too start with :).  http://our.umbraco.org/documentation/Reference/Mvc/surface-controllers

     

     

     

     

     

     

     

     

     

    Are you in a view or partial View.  I create a property on your model for nodeid and then post it as a hidden field with your form.  (this will save problems)

    Is there any reason why you have a defauly ActionResult Index?  If not remove it its adding complication. 

    public class HomePageSurfaceController : SurfaceController

    {       

    [AcceptVerbs("POST")]

    [HttpPost]

            public ActionResult Contact(FormCollection collection)
    {

    //DO SOME WORK HERE
    //I WANT TO PROCESS MY FORM DATA HERE
           }

    }

    The for the form post

    @Html.BeginForm("Contact","HomePageSurface", additional parameters)

    {

    }

    Hope this helps.  Any other questions please ask :)

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft