Skip to content

Instantly share code, notes, and snippets.

@nul800sebastiaan
Created February 9, 2015 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nul800sebastiaan/61680f773d3a97810270 to your computer and use it in GitHub Desktop.
Save nul800sebastiaan/61680f773d3a97810270 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();
}
}
}
@stoneprofits
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment