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
 

相关文章:

  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2023-03-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2021-09-11
相关资源
相似解决方案