第一步: Nuget引入:RazorEngine.NetCore
第二步:添加引用
using RazorEngine; using RazorEngine.Templating;
第三步:代码实现模版替换
public class FormModel : PageModel { public string HtmlCompile { set; get; } = string.Empty; public void OnGet([FromQuery] string formcode) { var template = "<b>@Model.Name</b>"; HtmlCompile = Engine.Razor.RunCompile(template, "templateKey1", null, new { Name = "测试" }); } }
第四步:shtml页面呈现
@Html.Raw(Model.HtmlCompile);
标签:Razor,string,NetCore,RazorEngine,HtmlCompile,解析,public From: https://www.cnblogs.com/microsoft-zh/p/18047382