Skip to content

Instantly share code, notes, and snippets.

@victorighalo
Created March 9, 2018 15:03
Show Gist options
  • Save victorighalo/accca381ae028d948e8a245815e014a8 to your computer and use it in GitHub Desktop.
Save victorighalo/accca381ae028d948e8a245815e014a8 to your computer and use it in GitHub Desktop.
Umbraco ContactController
using System;
using System.Web.Mvc;
using Umbraco.Web.Mvc;
using Wyzweb.Models;
namespace Wyzweb.Controllers
{
public class ContactController : SurfaceController
{
// GET: Contact
public ActionResult RenderContactForm()
{
return PartialView("_ContactForm");
}
//Submit form Action
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SubmitForm(Contact model)
{
if (ModelState.IsValid)
{
try
{
var response = true; //DO SOME AJAX REQUEST HERE OR DATABASE QUERY
if (response == true)
{
TempData.Clear();
TempData.Add("Response", "Success! Your message has been received.");
return CurrentUmbracoPage();
}
else
{
TempData.Clear();
TempData.Add("Response", "Error! Your form as not sent");
return CurrentUmbracoPage();
}
}
catch (Exception e)
{
TempData.Clear();
TempData.Add("Response", e.Message);
return CurrentUmbracoPage();
}
}
else
{
return CurrentUmbracoPage();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment