This project is read-only.

The name 'Html' does not exist in current context.

Dec 17, 2013 at 9:49 PM
Edited Dec 17, 2013 at 9:51 PM
I am trying to write a Web Api that will return Json Siren and Html. Using WebApiContrib its been going ok. Content comes back based on the content-type header. However when I try to use @Html in the Razor view I get the following exception.
Message=Unable to compile template. The name 'Html' does not exist in the current context

I found a stackoverflow discussion that seemed to be heading down the right road. (From a comment in the HtmlTemplateBase that I got from WebApiContrib. ) but I have tried a few things based on it with no luck. (I added the SetTemplateService in WebApiConfig) Can anyone point me in the right direction? I suspect its something fairly obvious. I am not a full on C# dev, just getting started.

The link to the stack discussion is:

Any help will be very much appreciated even if its - go and post in another forum.
Dec 18, 2013 at 4:10 PM
I got the @Html.Label working by moving my addition of formatters and HtmlTemplate to WebApiConfig.
            var viewParser = new RazorViewParser(baseTemplateType: typeof(HtmlTemplateBase<>));
            config.Formatters.Add(new RazorViewFormatter(viewParser: viewParser));
            config.Formatters.Add(new HtmlMediaTypeViewFormatter());
But @Html.DisplayFor still doesn't work - causing an exception.