refer : https://github.com/Antaris/RazorEngine
微软的模板编辑器。
Install-Package RazorEngine
using RazorEngine;
using RazorEngine.Templating; string templatePath = @"D:\Google Drive\learn\TDD\TDD\Views\Email\Index.cshtml";
string template = System.IO.File.ReadAllText(templatePath); //从文件中读出模板内容
string templateKey = "demo"; //取个名字
dynamic viewBag = new DynamicViewBag(); //创建viewBag
viewBag.value = ;
TemplateVM VM = new TemplateVM { name = "KKND" }; //创建 view model //编辑模板
string result = Engine.Razor.RunCompile(
template,
templateKey,
VM.GetType(),
VM,
(DynamicViewBag)viewBag //强转
); //替换值
VM = new TemplateVM { name = "zzzz" };
viewBag.value = ;
result = Engine.Razor.RunCompile(
template,
templateKey,
VM.GetType(),
VM,
(DynamicViewBag)viewBag
);
待研究测试 :
-缓存
-拿模板
-MVC能用的都可以用 ?