ASP.net MVC: Execute Razor from DB String?

为君一笑 提交于 2019-11-29 07:17:31
Buildstarted

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!