title: Building a contact form in Umbraco 6
body: <p>I'm trying to build a contact form in umbraco v6 by following the following <a href="http://our.umbraco.org/documentation/Reference/Mvc/forms" rel="nofollow">this</a> tutorial. The problems I'm having are that a) The form seems to be posting on load ie. I'm presented with required field errors on the form by default and b) when I actually populate the data and submit, I get a 404 not found error with the following location: Requested URL: /umbraco/RenderMvc</p>
  
  <p>Here is the code I have for my <strong>Model</strong>:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Web.Mvc;
  using System.Web.Security;
  using umbraco.cms.businesslogic.member;
  using System.ComponentModel.DataAnnotations;
  
  namespace CustomControls
  {
      public class ContactFormModel
      {
          [Required, Display(Name = "First name")]
          public string FirstName { get; set; }
  
          [Required, Display(Name = "Surname")]
          public string Surname { get; set; }
  
          [Required, Display(Name = "Company")]
          public string Company { get; set; }
  
          [Required, Display(Name = "Email address")]
          [DataType(DataType.EmailAddress)]        
          public string EmailAddress { get; set; }
  
          [Required, Display(Name = "Telephone")]
          public string Telephone { get; set; }
      }
  }
  </code></pre>
  
  <p>Here is my <strong>SurfaceController</strong> code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Web.Mvc;
  using System.Web.Security;
  using umbraco.cms.businesslogic.member;
  using System.ComponentModel.DataAnnotations;
  namespace CustomControls
  {
      public class ContactFormSurfaceController : Umbraco.Web.Mvc.SurfaceController
      {
          [HttpGet]
          [ActionName("ContactForm")]
          public ActionResult ContactFormGet(ContactFormModel model)
          {
              return PartialView("ContactForm", new ContactFormModel());            
          }
          [HttpPost]
          [ActionName("ContactForm")]
          public ActionResult ContactFormPost(ContactFormModel model)
          {    
              //model not valid, do not save, but return current umbraco page
              if (!ModelState.IsValid)
              {
                  //Perhaps you might want to add a custom message to the ViewBag
                  //which will be available on the View when it renders (since we're not 
                  //redirecting)     
                  TempData.Add("Status", "Invalid form data");
                  //return CurrentUmbracoPage();
                  return RedirectToCurrentUmbracoPage();
              }
              //if validation passes perform whatever logic
              //In this sample we keep it empty, but try setting a breakpoint to see what is posted here
              //Perhaps you might want to store some data in TempData which will be available 
              //in the View after the redirect below. An example might be to show a custom 'submit
              //successful' message on the View, for example:
              TempData.Add("Status", "Your form was successfully submitted at " + DateTime.Now);
              //redirect to current page to clear the form
              return RedirectToCurrentUmbracoPage();
  
              //Or redirect to specific page
              //return RedirectToUmbracoPage(1063);
          }
      }
  }
  </code></pre>
  
  <p>And finally here is my <strong>view</strong>:</p>
  
  <pre><code>@model CustomControls.ContactFormModel
  
  @using(Html.BeginUmbracoForm("SubmitContactForm", "ContactFormSurface"))
  {
      @Html.EditorFor(x =&gt; Model)
      &lt;input type="submit"/&gt;
  }
  
  &lt;p class="field-validation-error"&gt;@TempData["Status"]&lt;/p&gt;
  </code></pre>
  
  <p>This is the snippet of code I'm using in my template to render the form:</p>
  
  <pre><code>@Html.Action("ContactForm","ContactFormSurface")
  </code></pre>
  
  <p>Is anyone able to point out where I'm going wrong?</p>
  
  <p>Thanks</p>