ASP.net MVC: run Razor from a DB string?

I was thinking of giving end-users the ability to drop partial views (controls) into the information stored in the database. Is there a way to execute the row that I get from the database as part of the Razor view?

+6
source share
1 answer

Update (I forgot everything about it)

I asked this question earlier (which led me to create RazorEngine) Pulling a view from a database, not a file

I know at least two: RazorEngine , MvcMailer

I have a bias towards RazorEngine since I worked on this, but I have a lot easier on Github called RazorSharp (although it only supports C #)

All of them are pretty easy to use.

RazorEngine:

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

Mvcmailer

I have not used this, so I can not 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 . Because these libraries must exist outside of Mvc and therefore require more work to get them to work with these helpers. I can’t say anything about MvcMailer, but I suspect the situation is the same.

I hope for this help.

+8
source

Source: https://habr.com/ru/post/897878/


All Articles