首页 > 其他 > 详细

RazorEngine

时间:2014-08-16 16:18:50      阅读:220      评论:0      收藏:0      [点我收藏+]

TemplateServiceConfiguration templateConfig
= new TemplateServiceConfiguration { BaseTemplateType = typeof(HtmlTemplateBase<>) }; Razor.SetTemplateService(new TemplateService(templateConfig)); string template = "This is my sample template, Hello @Href()"; Razor.Compile(template,typeof(TestModel),"aa"); Console.WriteLine(Razor.Run("aa",new TestModel() { Name = "World"}));
    public class HtmlTemplateBase<T>:  TemplateBase<T>
    {
        
        public string Href()
        {
            var m = Model as TestModel;
            return m.Name.ToUpper();
        }

       
    }
    
    public class TestModel
    {
        public string Name
        {
            get;
            set;
        }
    }
修改Razorjs,不过他们引用的RazorEngine,太老的针对的是mvc3的,很多类都不对,去codeplex看了下,现在也搬家去github了。
另外Razorjs也不支持Session,到时候还要改下



主要是RazorEngine v2.1的设置模板的方式到3.0的时候变了
v2
Razor.SetTemplateBase(typeof(MyCustomTemplateBase<>));
v3
Razor.SetTemplateService
 

RazorEngine,布布扣,bubuko.com

RazorEngine

原文:http://www.cnblogs.com/peteryu007/p/3916428.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!