Reputation: 916
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 )
.
Upvotes: 1
Views: 357
Reputation: 156
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...
Upvotes: 1