Created
February 9, 2015 16:09
-
-
Save nul800sebastiaan/61680f773d3a97810270 to your computer and use it in GitHub Desktop.
TicketOrderController.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Web.Mvc; | |
using Umbraco.Course.Models; | |
using Umbraco.Web.Mvc; | |
namespace Awesome.FormDemo.Controllers | |
{ | |
public class TicketOrderController : SurfaceController | |
{ | |
[ChildActionOnly] | |
public ActionResult ShowOrderForm(TicketOrderModel model) | |
{ | |
model = model ?? new TicketOrderModel(); | |
if (model.Previous) | |
model.StepIndex--; | |
if (model.Next) | |
model.StepIndex++; | |
return View(model); | |
} | |
[HttpPost] | |
public ActionResult FormSubmit(TicketOrderModel model) | |
{ | |
//ignore validation or saving data when going backwards | |
if (model.Previous) | |
return CurrentUmbracoPage(); | |
var validationStep = string.Empty; | |
switch (model.StepIndex) | |
{ | |
case 0: | |
validationStep = "PersonalInfoStep"; | |
break; | |
case 1: | |
validationStep = "TicketOrderStep"; | |
break; | |
case 2: | |
validationStep = "TermsAgreementStep"; | |
break; | |
} | |
//remove all errors except for the current step | |
foreach (var key in ModelState.Keys.Where(k => k.StartsWith(string.Format("{0}.", validationStep)) == false)) | |
{ | |
ModelState[key].Errors.Clear(); | |
} | |
if (!ModelState.IsValid) | |
{ | |
return CurrentUmbracoPage(); | |
} | |
//Its the final step, do some saving | |
if (model.StepIndex == 2) | |
{ | |
//TODO: Do something with the form data | |
TempData.Add("CustomMessage", "Your form was successfully submitted at " + DateTime.Now); | |
return RedirectToCurrentUmbracoPage(); | |
} | |
return CurrentUmbracoPage(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I am having trouble getting the form to move to the next step. I get a page not found error, and it Requested URL: /umbraco/RenderMvc . do you have a working example up somewhere? I am running umbraco 7... Is it compatible?