4

Not entirely sure what's going on here; any help would be appreciated.

I'm trying to create a new .NET MVC web app. I was pretty sure I had it set up correctly, but I'm getting the following error:

The type 'System.Web.Mvc.ViewPage' is ambiguous: it could come from assembly 
'C:\MyProject\bin\System.Web.Mvc.DLL' or from assembly 
'C:\MyProject\bin\MyProject.DLL'. Please specify the assembly explicitly in the type name.

The source error it reports is as follows:

Line 1:  <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
Line 2:  
Line 3:  <asp:Content ID="indexContent" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

Anything stand out that I'm doing completely wrong?

4

9 回答 9

3

I suppose you named one of your page "ViewPage" is that the case?

And like @Jonathan mentioned, this smells:

Inherits="System.Web.Mvc.ViewPage"

On my MVC application, all the view pages have this instead:

Inherits="MySite.Views.Pages.Home"

Or something along the line. Your aspx page markup should have "Inherits" point to your code-behind class name, not the actual class that it is inheriting. The attribute name is rather misleading but its an artifact of earlier days.

于 2008-09-07T17:24:52.503 回答
2

Are you using a CodeBehind file, I don't see CodeBehind="" attribute where you are specifying the Inherits from? Then you have to point inherits to the class name of the codebehind.

Example:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MvcApplication4.Views.Home.Index" %>

Make sure the Inherits is fully qualified. It should be the namespace followed by the class name.

于 2008-09-07T17:20:48.753 回答
2

我正在运行 ASP.NET MVC Beta 并且也遇到了这个错误。

它是在我试图删除文件后面的代码以获取视图时发生的。我删除了@Page 指令中的“CodeBehind”属性,并将“Inherits”属性更改为指向 System.Web.Mvc.ViewPage,但在我的项目中保留了文件后面的实际 aspx.cs 代码。

此时,如果我尝试运行我的项目,则会收到您提到的错误。

我通过从我的项目中删除视图的 aspx.cs(代码隐藏)文件解决了这个错误。

于 2009-01-07T05:23:32.597 回答
2

System.Web.Mvc检查您对in的程序集引用web.config

我的明确指定2.0.0.0,但我的项目引用3.0.0.0

于 2012-11-09T14:59:59.777 回答
1

This error usually indicates a class naming conflict. You are referencing two namespaces or you created a class with the same name in another namespace that you are using. I would start by looking at what that could be.

于 2008-09-07T16:58:23.470 回答
1
 Inherits="System.Web.Mvc.ViewPage"

I'd imagine that this should be pointed at your View codebehind file class, not at the base ViewPage class.

于 2008-09-07T17:10:50.820 回答
1

在 Reflector 中打开 C:\MyProject\bin\MyProject.DLL 并查找 ViewPage 以查看您是否意外定义了一个。

于 2009-06-26T17:24:25.137 回答
0

不,这应该是结构性错误消息。

检查http://trikks.wordpress.com/2011/08/26/the-type-is-ambiguous-it-could-come-from-assembly-or-from-assembly-please-specify-the-assembly-explicitly -in-the-type-name/

于 2011-08-26T09:52:25.550 回答
0

本周我遇到了同样的错误。

我的 Webform.aspx 文件有一个生成的 Designer.cs 文件。在这个文件中,该类实际上被命名为“ViewPage”。删除设计器文件,或将类内容移动到 webform.aspx.cs 文件,我的错误就消失了。

只是把它放在那里,以防有人遇到这个错误。

于 2018-02-16T02:34:42.743 回答