Search code examples
razorengine

RazorEngine issues with @Html


I am using RazorEngine to render out some basic content (a very crude content management system).

It works great until I include any @Html syntax into markup.

If the markup contains an @html I get the following error:

Unable to compile template. The name 'Html' does not exist in the current context

This is the view that renders the markup:

@Model Models.ContentPage

@{
    ViewBag.Title = Model.MetaTitle;
    Layout = "~/Views/Shared/Templates/_" + Model.Layout + "Layout.cshtml";

}
@Html.Raw(RazorEngine.Razor.Parse(Model.Markup, Model))

I have seen on the Codeplex site for RazorEngine the use of @Html (I know the version on there is out of date and I got my version via nuget).

Any help on this would be great.


Solution

  • The Html and Url helper properties are actual features of MVC's implementation of Razor in their view engine. Out of the box, Html and Url are not currently supported without specialising a custom base template.

    The upcoming v3 release will be accompanied by an associated RazorEngine.Web release, which will hopefully include an MVC3 compatible base template with Html and Url support.

    The example I wrote on the project homepage, is purely an example of using a custom base template.

    You can find out more about v3 at https://github.com/Antaris/RazorEngine