Setting base type and setting namespaces
See original GitHub issueHi again. I’m trying to replace RazorEngine with RazorLight in my FormFactory project, but am getting some errors when I run my templates.
My templates are very similar to MVC views (in fact they are MVC views when I run them inside MVC, but I read them and change them when running as standalone templates), e.g. one might look like this:
@using System.ComponentModel.DataAnnotations
@using System.Linq
@using System.Xml.Linq
@using FormFactory
@{
@Model.GetCustomAttribute<DisplayAttribute>().Name
var value = Model.Value as XElement;
if (value != null) {
@Html.Raw(value.ToString())
}
}
So I have using statements, and am using @model and Model and also Html.
I got this to work with RazorEngine by making the template inherit from a base type with Html and Model on it. How can I set the base type with RazorEngine? It looks like Model is set from the .Parse(..., model) but that won’t work for Html
-Also I’m getting errors like - The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?). Is there a way to tell RazorEngine what assemblies to use?- caused by DataAnnotations having a different namespace in 451/standard
thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:17 (9 by maintainers)

Top Related StackOverflow Question
Part with injector is not correct. Is was just an example of how I use PreRenderCallback to fill in dependencies in templates.
Here is more complete example:
Yep, inheritance is supported.
Create a class:
In your view:
Replace dynamic with your model type, or leave it as it is.
About assemblies: It takes dependencies from entryAssembly, so make sure that you have everything there.