Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biapar/84e4d8638585d2efb403 to your computer and use it in GitHub Desktop.
Save biapar/84e4d8638585d2efb403 to your computer and use it in GitHub Desktop.
TicketOrderController.cs
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