Question

I'm rendering Spark templates in a console application and I'm trying to use RenderPartial like so:

${Html.RenderPartial("_mypartial.spark", myData)}

but I'm getting this error when compiling the view:

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

In the Shared\_global.spark I have added this imports:

<use namespace="System" />
<use namespace="System.Web.Mvc" />
<use namespace="System.Web.Mvc.Html" />
<use namespace="System.Collections.Generic" />
<use namespace="System.Linq" />

Everything else renders fine otherwise, it's just that Html is not defined.

It it makes any difference, I'm rendering this with an embedded NancyFX engine.

Was it helpful?

Solution

I believe the problem isn't within the view itself. I'm not familiar NancyFX engine, but all engines views should be using a base view. The default is in the web.config in the views folder:

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">

Of course you're not using razor, this is simply a comparison where Html exists on System.Web.Mvc.WebViewPage. How you configure NancyFX, the configuration needs to define the one that supports the HtmlHelpers (that either come with MVC or NancyFX, I'm not sure).

After taking a look at Gibhub It looks very similar:

<system.web.webPages.razor>
    <pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase">

And the NancyRazorViewBase has HtmlHelpers on it so it sounds very much like a configuration issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top