简体   繁体   中英

Render Razor Code inside HTML

I have some HTML that is saved on my DB, this is later modified and saved on a variable and finally it's printed on my view using @Html.Raw( Model.Page.Html ) .

The problem is, this HTML possess some Razor codes like ViewBag.Email . How could i render this Razor code before printing the HTML ? I have already tried to put that on an Partial View and call it inside the HTML and then print it but it also won't work.

Some people pointed me the RazorEngine lib but i couldn't make that work, i installed the version 3.7.7 but the documentation is a little confusing for me.

If RazorEngine is my best option could anyone please include an example of how to render my HTML before printing it ?

EDIT

This is an example of my problem: My contact page has a form inside. At some point in my Filter i checked to see if the request was from a mobile device and with this information i would set the type of the input on a ViewBag, for example:

<input type="@ViewBag.ITEmail" placeholder="E-mail" name="cEmail">

This HTML is fetched from my DB and passed to my Helpers to modify some information and then it's printed on my View using @Html.Raw( Model.Page.Html ) .

Razor views are dynamically built. Every time you edit your razor file it is compiled in background and built into new dll.

Basically you would have to trigger build process somehow that is normally triggered when cshtml file is changed. So, you would have to do that. Load and save a file. Or dig deep into internals...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM