Razor engine is a library that you can use to generate your cshtml files. For example you can use it for generating emails. It gives you the ability to add a layout (Masterpage) and then generate your templates based on the Layout.You can easily add it by nuget (add library package reference) .
You can download sample from Here:
https://github.com/Azadehkhojandi/RazorEngineTest
Resources:
https://github.com/Antaris/RazorEngine
|
You can download sample from Here:
https://github.com/Azadehkhojandi/RazorEngineTest
Resources:
https://github.com/Antaris/RazorEngine
Comments
https://github.com/Azadehkhojandi/RazorEngineTest/downloads
What's the version of your visual studio ?
It works fine with
VS2010 and RazorEngine.3.0.8
Check infrastructure project
Your test project [https://github.com/Azadehkhojandi/RazorEngineTest/downloads] works fine actually (VS11 here), the issue i had seemed to relate to version 3.0.0, where _Layout could not be resolved, additionally, the signature for TemplateService.Parse was different. This lead to a bit of confusion my side on which version of the RazorEngine i should use. (also, there is a System.Web.Razor namespace nowadays, so still somewhat confused on what i should be using, do you have any thoughts on this?)
Thanks again for your post, there doesn't appear to be a lot of information out there with many working examples at this time, so your example is hugely appreciated.
Cheers
https://github.com/Antaris/RazorEngine/issues/71
do you want it for generating email?
Was looking at the Razor Engine as a more flexible alternative to the built-in ASP.NET MVC Razor implementation (which is effectively bound to a Controller's Actions).
I was just after a more generic templating solution that would work outside of MVC, handle partial views, and run in a similar fashion to how other templating frameworks operate. (django, mustache, ejs/jade, etc).
And yup, email generation is one of the things i plan to use it for :D
you should be careful an do a proper load testing before pushing into live site.
It might be helpful if you look at Nvelocity (http://docs.castleproject.org/MonoRail.NVelocity.ashx).
I typically cache template output, but for non cached templates (where dynamic or real-time data passes through), i do compile them first rather than compile and parse from scratch each time. The compile step is expensive after all.
So my compiled template(s) exist for the lifetime of the application, and with this, I get rough throughput of about 80k parses per second for a basic template with a partial render (@section, i.e) and some dynamic data.
Are you saying that you have noticed issues with performance even after compilation?
Cheers mate
I recommend to use razor engine dll asynchronously.if you want to use it like the following you may have problems for concurrent calls.
(1)get user registration details then (2)send email wait for razor dll to compile and parse the template with data and then (3)redirect to thank you page.
I suggest
(1)get user registration details then (2) call send message method ,add sending message with registration data in queue (you can use RabbitMQ) (3)redirect to thank you page