Created
March 19, 2019 05:51
-
-
Save mikebrind/0fbf8744015520ad951a8ea3238affa7 to your computer and use it in GitHub Desktop.
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.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.Mvc.RazorPages; | |
using RazorPartialToString.Services; | |
namespace RazorPartialToString.Pages | |
{ | |
public class ContactModel : PageModel | |
{ | |
private readonly IRazorPartialToStringRenderer _renderer; | |
private readonly IEmailService _emailer; | |
public ContactModel(IRazorPartialToStringRenderer renderer, IEmailService emailer) | |
{ | |
_renderer = renderer; | |
_emailer = emailer; | |
} | |
[BindProperty] | |
public ContactForm ContactForm { get; set; } | |
[TempData] | |
public string PostResult {get;set;} | |
public async Task<IActionResult> OnPostAsync() | |
{ | |
var body = await _renderer.RenderPartialToStringAsync("_ContactEmailPartial", ContactForm); | |
await _emailer.SendAsync(ContactForm.Name, ContactForm.Email, ContactForm.Subject, body); | |
PostResult = "Check your specified pickup directory"; | |
return RedirectToPage(); | |
} | |
} | |
public class ContactForm | |
{ | |
public string Email { get; set; } | |
public string Message { get; set; } | |
public string Name { get; set; } | |
public string Subject { get; set; } | |
public Priority Priority { get; set; } | |
} | |
public enum Priority | |
{ | |
Low, Medium, High | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment