2

I do have some text(template), which looks like "Hello @FirstName, Welcome to @Address". The original plan was to put this text file in a view-bag and pass it through razor and it will do the job.

Now, The problem that I am facing is that my team wants this transformation to be handled by a Service, So there is no controller and there is no view here BUT there is a need to use Razor view engine's capability to replace all @ with server variables.

This sounded weird to me as well but is there any way that I can extract this capability of Razor view in a way that I can use this functionality in a restful service rather than sending this data to a .cshtml file?

tereško
  • 57,247
  • 24
  • 95
  • 149
Lost
  • 10,143
  • 29
  • 109
  • 178

2 Answers2

2

This is possible indeed.

Rick Strahl blogged about hosting the Razor Engine in non-web applications.

And of course, this has been asked here before.

Community
  • 1
  • 1
Oded
  • 477,625
  • 97
  • 867
  • 998
  • Actually, I visited the blog and I liked it but he does not mention anywhere that where did he get reference for RazorTemplateBase? i have no idea if I need to download a package or something? – Lost Mar 07 '12 at 21:19
  • @Californicated - He does mention it, under the "Installing The Razor Template Engine" heading. Taken from http://www.microsoft.com/web/gallery/install.aspx – Oded Mar 07 '12 at 22:00
  • The only razor app in the library that I can see is razorC.Net. is it the one? – Lost Mar 07 '12 at 22:21
  • Actually, I came across something called @razorEngineon following URL:http://razorengine.codeplex.com/wikipage?title=Quick%20Start%20Guide&referringTitle=Documentation. It's awesome and it worked for me. – Lost Mar 07 '12 at 23:46
1

Yes, it is possbible. The necessary steps to do that is described here: Razor View Engine without MVC at all.

driis
  • 156,816
  • 44
  • 266
  • 336