Created
March 9, 2018 15:03
-
-
Save victorighalo/accca381ae028d948e8a245815e014a8 to your computer and use it in GitHub Desktop.
Umbraco ContactController
This file contains 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.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