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
services.AddMvc().AddRazorPagesOptions(options => | |
{ | |
options.Conventions.Add(new PageRouteTransformerConvention(new HyphenateRouteParameterTransformer())); | |
}); |
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 Microsoft.AspNetCore.Routing; | |
using System.Text.RegularExpressions; | |
public class HyphenateRouteParameterTransformer : IOutboundParameterTransformer | |
{ | |
public string TransformOutbound(object value) | |
{ | |
if (value == null) | |
{ | |
return null; |
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
public interface IProductService | |
{ | |
List<string> GetProductNames(); | |
} | |
public class ProductService : IProductService | |
{ | |
public List<string> GetProductNames() | |
{ | |
return new List<string> |
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
public class ProductConstraint : IRouteConstraint | |
{ | |
private readonly IProductService productService; | |
public ProductConstraint(IProductService productService) | |
{ | |
this.productService = productService; | |
} | |
public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection) |
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.Net.Mail; | |
using System.Threading.Tasks; | |
namespace RazorPartialToString.Services | |
{ | |
public class DemoEmailService : IEmailService | |
{ | |
public async Task SendAsync(string email, string name, string subject, string body) | |
{ | |
using (var smtp = new SmtpClient()) | |
{ |
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.Threading.Tasks; | |
namespace RazorPartialToString.Services | |
{ | |
public interface IEmailService | |
{ | |
Task SendAsync(string email, string name, string subject, string body); | |
} | |
} |
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
@model ContactForm | |
@{ | |
Layout = null; | |
} | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Contact Email</title> | |
<style> | |
body{font-family:Calibri, sans-serif;font-size: 11pt;color: #555;} |
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
@page | |
@model RazorPartialToString.Pages.ContactModel | |
@if(TempData["PostResult"] == null) | |
{ | |
<form method="post"> | |
<label asp-for="ContactForm.Name"></label> | |
<div class="form-group"> | |
<input asp-for="ContactForm.Name"> | |
</div> | |
<label asp-for="ContactForm.Email"></label> |
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 |
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
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest); | |
services.AddTransient<IEmailService, DemoEmailService>(); | |
services.AddTransient<IRazorPartialToStringRenderer, RazorPartialToStringRenderer>(); |