I have code like this. Is there a way to make it easier to write and maintain? Using C# .NET 3.5.
string header(string title)
{
StringWriter s = new Stri
With the introduction of Razor in ASP.net MVC, the best way to write HTML in C# is with the Razor Engine.
string templatePath = $@"{Directory.GetCurrentDirectory()}\EmailTemplates";
IRazorLightEngine engine = EngineFactory.CreatePhysical(templatePath);
var model = new Notification
{
Name = "Jone",
Title = "Test Email",
Content = "This is a test"
};
string result = engine.Parse("template.cshtml", model);
Template:
Dear @Model.Name, you have a notification.
@Model.Title
@Model.Content
Date:@DateTime.Now
For a complete sample, see here