【问题标题】:Parse Razor string in ASP.NET core在 ASP.NET 核心中解析 Razor 字符串
【发布时间】:2016-06-29 12:22:37
【问题描述】:

在 ASP.NET MVC 中,我可以像这样解析 Razor 脚本:

string template = "It is @DateTime.Now.ToString()";
string result = Razor.Parse(template);

但核心中不存在这种静态。

我也读过这个post,但在我的情况下,视图代码是一个字符串,所以我不能使用ICompositeViewEngine 中的findget 视图方法。

关于如何在核心中解析视图字符串有什么建议吗?

【问题讨论】:

标签: c# asp.net-mvc razor asp.net-core razorengine


【解决方案1】:

我已经回答了Here的问题

今天我已经完成了可以解决您问题的库。您可以在 ASP.NET 之外使用它,因为它没有 对它的依赖

你可以这样使用它

string template = "It is @DateTime.Now.ToString()";
string result = new LightRazorEngine().ParseString(template);

更多:https://github.com/toddams/RazorLight

【讨论】:

    猜你喜欢
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多