Templating using new RazorEngine API

前端 未结 3 1866
梦毁少年i
梦毁少年i 2020-12-12 16:15

Some time ago rendering a template using RazorEngine was as easy as:

string s = RazorEngine.Razor.Parse()

However, for some re

3条回答
  •  执念已碎
    2020-12-12 16:53

    Building on @turdus-merula's answer, I wanted the temp files to be cleaned up when the default AppDomain is unloaded. I disabled the temp file locking in the config, which allows the temp folder to be deleted.

    var config = new TemplateServiceConfiguration
    {
        TemplateManager = new ResolvePathTemplateManager(new[] {"EmailTemplates"}),
        DisableTempFileLocking = true
    };
    
    Engine.Razor = RazorEngineService.Create(config);
    
    var html = Engine.Razor.RunCompile("Test.cshtml", null, model);
    

提交回复
热议问题