Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何用RazorEngineService替换TemplateService?_C#_Razor_Html Email - Fatal编程技术网

C# 如何用RazorEngineService替换TemplateService?

C# 如何用RazorEngineService替换TemplateService?,c#,razor,html-email,C#,Razor,Html Email,我有如下所示的代码,我想用更新的RazorEngineService替换TemplateService。你能告诉我如何在我的代码中替换它吗 PS:我已经检查过了,但是当我试图重构代码以获得RazorEngineService时,我遇到了一些异常 public class ReminderEmail { string templateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmailTemplate

我有如下所示的代码,我想用更新的RazorEngineService替换TemplateService。你能告诉我如何在我的代码中替换它吗

PS:我已经检查过了,但是当我试图重构代码以获得RazorEngineService时,我遇到了一些异常

public class ReminderEmail
{
    string templateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EmailTemplates");
    string templateFilePath;
    ReminderEmailModel model;

    public ReminderEmail(ReminderEmailModel model)
    {
        this.model = model;
        try
        {
            templateFilePath = Path.Combine(templateFolderPath, "ReminderEmail.cshtml");
        }
        catch (FileNotFoundException e)
        {
            //TODO: log file not found here
        }
    }


    public string GetHtmlBody()
    {
        var templateService = new TemplateService();
        var emailHtmlBody = templateService.Parse(File.ReadAllText(templateFilePath), model, null, null);
        return emailHtmlBody;
    }
}
见: