Last post Jul 20, 2010 08:17 PM by Vimpyboy
Jul 19, 2010 06:23 PM|CyberKral|LINK
Is there a way to render dynamic content like :
is now @DateTime.Now.ToString()</p>")
This would be usefull to render content extracted form database.
Jul 20, 2010 03:16 AM|davidfowl|LINK
that you are trying to solve?
Jul 20, 2010 04:32 AM|Vimpyboy|LINK
As David Fowler says, It´s really not recommended to do this. You can use the parsers for Razor to to this though (I have used the parsers myself without problems).
The easiest way to do it is to generate a .cshtml file and save it on the server.
Can you explain your problem?
Jul 20, 2010 07:05 AM|CyberKral|LINK
I want to post dynamic contents from the client, store in the database and render later when the content page is
If I generate a .cshtml file every time I need to render, it will not be efficient.
Jul 20, 2010 07:31 AM|Vimpyboy|LINK
If I was going to do something like that I should probably write a new View Engine which uses the parsers in Razor to render the text.
You can find a great blog post about how to use the Razor APIs here:
Instead of saving them as a text file you can display them as a view using a custom ViewEngine (this is a blog post I wrote in swedish, but you could read it in english using Google Translate):
If you don´t want to write a custom ViewEngine you could also create a custom ActionResult:
Jul 20, 2010 11:49 AM|davidfowl|LINK
Do you have a specific example of what you want to do? I'm sure there is another way to do it. You say it will not be efficient, but I'm not even sure what you are trying to achieve and I'm sure you haven't measured anything.
Jul 20, 2010 07:05 PM|CyberKral|LINK
I have extended html syntax for my need, here a simplified exemple:
In my asp.net project, the Page_Load of default.aspx contains
string html = Parse(xmlData);
Can I implement this with the razor syntax?
Jul 20, 2010 07:07 PM|Vimpyboy|LINK
If you are using your own syntax, I think you should have your own ViewEngine which uses the parser you have.
Jul 20, 2010 07:40 PM|CyberKral|LINK
Thanks Vimpyboy, I will try to write my own ViewEngine.
My second problem is with contents that come from database.
string html = GetHtmlFromDatabase(contentId);
Is there an equivalent of this in the razor syntax?
Jul 20, 2010 08:17 PM|Vimpyboy|LINK
You could just print that out. If you don´t want it to be HTML encoded you will need to return it as a IHtmlString, using for example HtmlString:
var text = new HtmlString(GetHtmlFromDatabase(contentId));