using System; using RazorEngine; using RazorEngine.Templating; namespace ConsoleCodeGen.RazorTest { /// <summary> /// Razor模板测试01 /// </summary> public class RazorTest1 { public static void Test() { string template1 = "Hello, World! @Model.Name"; string strContent = Engine.Razor.RunCompile(template1, "key1", null, new { Name = "ok" }); Console.WriteLine("当前模板结果是"); Console.WriteLine(strContent); } } }
template1 : 是模板 @Model是模型
Engine.Razor.RunCompile中参数
template1: 是模板
key1 : 是模板对应的key
new {Name="Ok"} 是参数值