“The name 'Html' does not exist in the cur

2019-08-31 17:57发布

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.

1条回答
我命由我不由天
2楼-- · 2019-08-31 18:06

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.

查看更多
登录 后发表回答