I'd like to use the following Razor template with RazorEngine:
@{
Layout = null;
}
@Html.Raw(MyNamespace.MyClass.SomePropertyWithHtml)
When I call it I get 2 errors - one complaining it can't handle Layout, and another complaining it doesn't know how to deal with the Html helper.
There are other questions and answers here suggesting this is possible in v3, and I'm using the current package on NuGet - v3.0.8 - but it isn't clear how this is done. Currently I'm calling it like so:
string html = RazorEngine.Razor.Parse(File.ReadAllText(path));
Other answers suggest using Razor.SetBaseTemplate first, which does not appear in current source or the 3.0 branch on git. Looking at the code I see code referencing layouts and sections, but the layout code appears to depend on resolving a template by name, while what I'm trying to do doesn't even need to resolve a template - I just need it to cope with the Layout = null. The code also includes a MvcTemplateBase that appears to offer an HtmlHelper in the Web project - but it's the sole class in that project and not referenced anywhere in the Web or Core projects.
This similar question: RazorEngine issues with @Html
Just links to the homepage saying you can find out more there - the homepage is just a short sentence describing the project.
So, how do I parse the above Razor view with RazorEngine v3.0?
@inherits MvcTemplateBase<T>
at the top of your file to use it. – Hesiod