Skip to content

Instantly share code, notes, and snippets.

@mikebrind
Created March 19, 2019 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikebrind/0fbf8744015520ad951a8ea3238affa7 to your computer and use it in GitHub Desktop.
Save mikebrind/0fbf8744015520ad951a8ea3238affa7 to your computer and use it in GitHub Desktop.
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