我试图使用来自MasterPage项目的现有WebForms,并将其与添加到同一解决方案中的MVC区域一起使用。
我读过这个博客,目前我一直在研究如何将两者连接起来。我在Shared文件夹中添加了扩展方法和他建议的所有项目。
在他的示例Shared/RazorView.aspx文件中,我在这一行中得到了两个错误。
<% Html.RenderPartial((string) ViewBag._ViewName); %>
`The name 'Html' does not exist in the current context`
`The name 'ViewBag' does not exist in the current context`如何引用MasterPage,或如何设置视图,以便将MasterPage用作部分内容?
发布于 2015-04-20 21:53:49
你快到了。您只需配置ASP.NET WebForms,以了解MVC在Views/web.config中的作用。
<system.web>
<pages pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
<namespaces>
<add namespace="System.Web.Mvc.Html"/>
</namespaces>
</pages>
</system.web>为了使RenderPartial扩展方法工作,还需要添加名称空间System.Web.Mvc.Html。
https://stackoverflow.com/questions/29758483
复制相似问题