Skip to content

Instantly share code, notes, and snippets.

@daniel-packard
Created March 23, 2016 00:07
Show Gist options
  • Save daniel-packard/0374c7fa3efdd0aadfb5 to your computer and use it in GitHub Desktop.
Save daniel-packard/0374c7fa3efdd0aadfb5 to your computer and use it in GitHub Desktop.
Should the HttpPost Contact method look like this instead?
[HttpPost]
public IActionResult Contact(ContactViewModel model)
{
var email = Startup.Configuration["AppSettings:SiteEmailAddress"];
if (string.IsNullOrWhiteSpace(email))
{
ModelState.AddModelError("", "Unable to send message: invalid server configuration.");
}
if (ModelState.IsValid)
{
if (_mailService.SendMail(email, email, $"contact message from {model.Name}", model.Message))
{
ModelState.Clear();
ViewBag.Message = "Message sent - thank you!!!";
}
}
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment