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!