【发布时间】:2011-07-06 18:56:53
【问题描述】:
我正在尝试通过 RenderPartial 调用 @Html.RenderPartial("SomePage.cshtml") 在我的网站(不是 Web 应用程序)中包含一些可重用的代码。在asp中,我只能使用#include virtual="somefile.asp"。但是,我收到以下错误消息。
编译器错误消息:CS1061:'System.Web.WebPages.Html.HtmlHelper' 不包含定义 'RenderPartial' 并且没有扩展 方法“RenderPartial”接受 类型的第一个参数 'System.Web.WebPages.Html.HtmlHelper' 可以找到(您是否缺少 使用指令或程序集 参考?)
我已在我的 web.config 文件中包含所有适当的引用。
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<pages>
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Collections.Generic"/>
</namespaces>
</pages>
RenderPartial 是否仅在“Web 应用程序”而不是“网站”中可用?
有没有更好的方法在整个站点中重用代码?
@RenderSection 在我的情况下不起作用,因为我使用的布局不会在同一位置重用代码。
【问题讨论】:
-
是
Web.config位于Views目录中的那个吗? -
注意,MVC官方只支持Web Application项目模型。
标签: asp.net-mvc razor renderpartial