RazorEngine 学习笔记

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 = 55;
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 = 99999;
result = Engine.Razor.RunCompile(
        template,
        templateKey,
        VM.GetType(),
        VM,
        (DynamicViewBag)viewBag
);

待研究测试 : 

-缓存

-拿模板

-MVC能用的都可以用 ?

 

转载于:https://www.cnblogs.com/keatkeat/p/5403422.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值