我一直在尝试实现this解决方案是拥有一个使用 asp 母版页的 razor View 页面。我遇到的问题是母版页无法继承MVC ViewMasterPage:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="System.Web.Mvc.ViewMasterPage" %>
Parser Error Message: The type 'System.Web.Mvc.ViewMasterPage' is ambiguous: it could come from assembly 'C:\Projects\OpenDataPortal\OpenDataPortal\bin\System.Web.Mvc.DLL' or from assembly 'C:\Projects\OpenDataPortal\OpenDataPortal\bin\OpenDataPortal.DLL'. Please specify the assembly explicitly in the type name.
我使用 .NET Reflector 检查了此 ViewMasterPage
并确定它包含 Razor 页面上使用的所有 Html 帮助程序等。因此,这应该允许我在解决方案中使用此母版页的 RazorView.aspx 页面上执行以下操作(Html 帮助程序和 ViewBag):
<% Html.RenderPartial((string) ViewBag._ViewName); %>
我还确定 web.config 中的 MVC 程序集应该没有任何问题:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>
我也不确定母版页和/或 RazorView.aspx 页面的代码隐藏和/或设计器是否会导致任何问题。
最佳答案
似乎其他 DLL 也包含来自 System.Web.Mvc 命名空间的类型(很可能他们在发布程序集时执行了 ILMerge,但不确定为什么)。因此,您需要通过在 Inherits
中提供完整的程序集名称来消除歧义:
Inherits="System.Web.Mvc.ViewMasterPage, System.Web.Mvc, version=5.2.2.0, culture=neutral, publickeytoken=31bf3856ad364e35"
关于c# - 在 Razor View 上使用母版页时,system.web.mvc.dll 和 Solution_name.dll 之间不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26086285/