Compile Razor Code that is saved in Database.

Vlachopoulos Dimitris 1 Reputation point
2022-06-27T15:24:35.747+00:00

Hello guys. I am developing a Custom CMS for my Job in .NET 5 with Razor Pages.

I was wondering if I could to create something like short tags from Wordpress and I thought ViewComponents. Well I have created a ViewComponent that have the html code of a carousel but when I save the content of the page in Database and then I try to retrieve that with @azzedinehtmlsql .Raw(Model.Text) this ViewComponent does not compiled. I understand why this happens but I wonder If exists any way to do that instead of I write a ton of code to create something like short tags.

Developer technologies ASP.NET ASP.NET Core
Developer technologies C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-06-27T16:31:51.357+00:00

    Here are a few options

    No matter what path you take customization will be needed unless you pursue a paid service.

    0 comments No comments

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-06-27T19:37:11.273+00:00

    you should be able to implement with razor engine

    https://github.com/Antaris/RazorEngine

    one caveat, razor pages and templates are compiled and loaded into memory, for the life of the application (unlike Wordpress where the template is the the life of the request). this mens you must manage the memory use well.

    so you can build a CMS system for small small sites with Razor page technology, but large sites will have issues.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.