如何在 MVC 中使用模型解析 Razor 字符串

How to Parse Razor string using Model in MVC

我的项目中有以下剃须刀字符串,如下所示。

string razorString = "This mail is from @Model.email";
var model = new { email = "mann@gmail.com" };

我需要用给定的模型解析 razorString。我在 RazorEngine 中看到过 Razor.Parse 方法,但该方法现在已过时并替换为 Engine.Razor。那么我怎样才能用新方法达到同样的效果。请建议。

使用 Engine.Razor.RunCompile(template, "templateKey", null, model) 后出现以下错误

string template = "This mail is from @Model.email";
var model = new { email = "mann@gmail.com" };

string result = Engine.Razor.RunCompile(template, "templateKey", null, model);