RazorEngine.NetCore最简单的示例

所属源码: RazorEngine
sam 2022-04-17 22:02:30

直接代码

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"} 是参数值

回帖
  • 消灭零回复
相关文章