public class Person
    {
        public string Name
        {
            get;
            set;
        }
        public string Code
        {
            get;
            set;
        }
    }
    var templateServiceConfiguration = new TemplateServiceConfiguration();
        //templateServiceConfiguration.Namespaces.Add("System.Configuration");

        var body = string.Empty;

        using (var service = RazorEngineService.Create(templateServiceConfiguration))
        {
            body = service.RunCompile(
@"Hello @Model.Name @Model.Code , 
welcome to RazorEngine!","hello1",
                typeof(Person),new Person(){Name="aaaa",Code="111"});
            Console.WriteLine(body);
Console.WriteLine(service.RunCompile(
"hello1",typeof(Person),new Person(){Name="bbbb",Code="222"})); }

输出

 Hello aaaa 111 , 
welcome to RazorEngine!
Hello bbbb 222 , 
welcome to RazorEngine!

相关文章:

  • 2021-12-13
  • 2021-08-01
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2022-02-27
  • 2021-11-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-12
  • 2021-08-13
相关资源
相似解决方案