“名称"Html"在当前上下文中不存在"例外 [英] "The name 'Html' does not exist in the current context" exception
问题描述
我正在控制台应用程序中渲染Spark
模板,并且尝试像这样使用RenderPartial
:
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
在Shared\_global.spark
中,我添加了以下导入:
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" />
其他所有内容都可以正常显示,只是未定义Html
.
Everything else renders fine otherwise, it's just that Html
is not defined.
它有什么区别,我使用嵌入式NancyFX
引擎对此进行渲染.
It it makes any difference, I'm rendering this with an embedded NancyFX
engine.
推荐答案
我认为问题不在视图本身之内.我对NancyFX引擎不熟悉,但是所有引擎视图都应使用基本视图.默认值是在views文件夹的web.config中:
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">
当然您不是在使用剃刀,这只是Html
在System.Web.Mvc.WebViewPage
上的比较.如何配置NancyFX,该配置需要定义一个支持HtmlHelpers
的配置(我不确定MVC还是NancyFX随附).
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).
在看Gibhub之后看起来非常相似:
<system.web.webPages.razor>
<pages pageBaseType="Nancy.ViewEngines.Razor.NancyRazorViewBase">
NancyRazorViewBase
具有
And the NancyRazorViewBase
has HtmlHelpers
on it so it sounds very much like a configuration issue.
这篇关于“名称"Html"在当前上下文中不存在"例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!