RazorEngine 3.6.5.0

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!

posted on 2015-04-17 13:10  聪明的大熊  阅读(339)  评论(0编辑  收藏  举报