RazorEngine: can be used in a Webforms application?

Can I use the Razor engine ( razorengine.codeplex.com ) in a webforms web application? I use files to define patterns, for example.

Sample.cshtml

<h1>Hello</h1>

Or sample2.cshtml (with inheritance to include intellisense)

@inherits SomeBaseClass<SomeModelClass>
<h1>Hello @Model.SomeProperty</h1>

When starting the application, I compile the templates:

//get files and loop
RazorEngine.Razor.Compile(templateString, razorPath);

In the user control code that I download / parse the template:

RazorEngine.Razor.Run<SomeModelClass>(model, razorPath);

Problem:

Sample.cshtml gives the following exception:

The type "ASP._Page_razor_Sample_cshtml" is not inherited from "System.Web.UI.UserControl".

Sample2.cshtml gives the following exception (the code where the exception occurs is retrieved below from the compiled cshtml source ...):

CS0103: the name "Context" does not exist in the current context

Line 37:         protected ASP.global_asax ApplicationInstance {
Line 38:             get {
Line 39:                 return ((ASP.global_asax)(Context.ApplicationInstance));
Line 40:             }
Line 41:         }

Razor ?

+3
2

Razor. somehwere CMS, (!). path , , ... , , ...

0

All Articles