c# - 在 Razor View 上使用母版页时,system.web.mvc.dll 和 Solution_name.dll 之间不明确

标签 c# asp.net asp.net-mvc razor master-pages

我一直在尝试实现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/

相关文章:

c# - 如何在 View 中引用隐式类型模型

c# - 将字符串发送到 PHP 页面并让 PHP 页面显示该字符串

c# - ActionLink可选参数错误

asp.net - 确定在 ASP.NET 中导致重定向的错误

asp.net - 为什么在调用返回 JSON 结果的基于外部 IIS 的 MVC Controller 时会收到 403 禁止消息

c# - 使用 Get 将 ASP.Net MVC 中的 ViewModel 从一个 View 传递到另一个 View

c# - 两次实现一个显式接口(interface)来实现 "virtual"行为是否是一个丑陋的 hack?

c# - 使用 LINQ 如何从集合实体创建实体的一个特定字段的列表

c# - 无效操作异常 : Incorrect Content-Type: ASP. NET Core

c# - 使用 jquery、ajax 和 asp.net 的评论框?