Hosting the Razor View Engine using a view model?

Using the @model tag is actually a shortcut for the @inherits tag.

Up vote 1 down vote favorite share g+ share fb share tw.

I'd like to use the Razor View Engine outside of ASP. NET MVC to generate HTML for emails, I like the syntax and it seems unnecessary to use another templating engine when I already have Razor in my project. So I looked around and found this guide on how to do it.. blog.andrewnurse.net/2010/11/16/HostingR... Unfortunately I can't find any way of specifying a view model, which is sad because I would really, really like to have strongly typed views even for my emails.

So is there any way of parsing Razor templates outside of ASP. NET MVC with strongly typed view models or is it so much trouble it's not worth the hassle? Asp.

Net-mvc-3 razor link|improve this question edited Dec 15 '10 at 10:12 asked Dec 15 '10 at 10:06weazl309213 57% accept rate.

Have a look at razorengine.codeplex.com for a prebuilt package that hosts razor outside of MVC – BuildStarted Dec 15 '10 at 15:38.

Using the @model tag is actually a shortcut for the @inherits tag. You specify the class, your generated class will inherit from from the class specified with @inherits. So if you specify @inherits MyTemplate MyTemplate should look like: class MyTemplate { public T Model { get; set; } public abstract void Execute(); public virtual void Write(object value) { WriteLiteral(value); } public virtual void WriteLiteral(object value) { // Actual writing goes here } } The result from the razor parsing, you need to compile, and create an instance from.

After you created the instance you can set the Model property, and call Execute to generate the result, how and what you generate is up to you.

Thanks, works like a charm. :) – weazl Dec 15 '10 at 13:14.

With the last stable RazorEngine it is enough to specify @inherits RazorEngine.Templating. TemplateBase unless you need some more functionality.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions