ASP.net MVC:从数据库字符串执行 Razor?

发布于 2024-12-05 23:57:22 字数 75 浏览 2 评论 0原文

我正在考虑让最终用户能够将部分视图(控件)放入数据库中存储的信息中。有没有办法执行我从数据库获取的字符串作为 Razor 视图的一部分?

I was thinking about giving end users the ability to drop Partial Views (controls) into the information being stored in the database. Is there a way to execute a string I get from the database as part of the Razor view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛清羽墨安 2024-12-12 23:57:22

更新(我忘记了这一切)

我之前问过这个问题(这导致我创建 RazorEngine)从数据库而不是文件中提取视图

我知道至少有两个: RazorEngineMvcMailer

我对 RazorEngine 有偏见,因为它我已经开发过一个,但我在 Github 上有一个更简单的,名为 RazorSharp(虽然它只支持c#)

这些都非常容易使用。

RazorEngine:

string result = RazorEngine.Razor.Parse(razorTemplate, new { Name = "World" });

MvcMailer

我没有使用过这个,所以我无法提供帮助。

RazorSharp

RazorSharp 还支持母版页。

string result = RazorSharp.Razor.Parse(new { Name = "World" }, 
                                       razorTemplate, 
                                       masterTemplate); //master template not required

RazorSharp 和 RazorEngine 都不支持任何 Mvc 帮助程序,例如 HtmlUrl。由于这些库应该存在于 Mvc 之外,因此需要更多的工作才能让它们与这些助手一起工作。我不能对 MvcMailer 说什么,但我怀疑情况是一样的。

希望这些有帮助。

Update (I forgot all about this)

I had asked this question previously (which lead me to create RazorEngine) Pulling a View from a database rather than a file

I know of at least two: RazorEngine, MvcMailer

I have a bias towards RazorEngine as it's one that I've worked on but I have a much simpler one at Github called RazorSharp (though it only supports c#)

These are all pretty easy to use.

RazorEngine:

string result = RazorEngine.Razor.Parse(razorTemplate, new { Name = "World" });

MvcMailer

I haven't used this one so I can't help.

RazorSharp

RazorSharp also supports master pages.

string result = RazorSharp.Razor.Parse(new { Name = "World" }, 
                                       razorTemplate, 
                                       masterTemplate); //master template not required

Neither RazorSharp, nor RazorEngine support any of the Mvc helpers such as Html and Url. Since these libraries are supposed to exist outside of Mvc and thus require more work to get them to work with those helpers. I can't say anything about MvcMailer but I suspect the situation is the same.

Hope these help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文