错误“'~/Views/Page/home.aspx' 中的视图必须派生自 ViewPage、ViewPage<TViewData>、ViewUserControl 或 ViewUserControl<TViewData>" [英] Error "The view at '~/Views/Page/home.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>"
问题描述
我刚刚安装了 MVC2 并且我有一个看起来像这样的视图
I've just installed MVC2 and I've got a view that looks like this
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Home.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Home</h2>
</asp:Content>
控制器只是返回视图.但是当我运行该页面时,出现此错误:
And the controller is just returning the view. But when I run the page I get this error:
System.InvalidOperationException:~/Views/Page/home.aspx"中的视图必须派生自 ViewPage、ViewPage、ViewUserControl 或 ViewUserControl.
System.InvalidOperationException: The view at '~/Views/Page/home.aspx' must derive from ViewPage, ViewPage, ViewUserControl, or ViewUserControl.
推荐答案
您可能会无意中将两个版本的 MVC 框架加载到同一个应用程序中.要确认,请从 http://aspnet.codeplex.com/releases/view/41742 下载 MVC 2 Futures.此 ZIP 文件中有一个文件 MvcDiagnostics.aspx.
You might unintentionally have two versions of the MVC framework loaded into the same application. To confirm, download MVC 2 Futures from http://aspnet.codeplex.com/releases/view/41742. There is a file MvcDiagnostics.aspx in this ZIP file.
- 将 MvcDiagnostics.aspx 复制到您的网络项目的根目录.
- 重现错误.
- 重现错误后,转到/MvcDiagnostics.aspx 并查看它是否抱怨(以粗体红色字体显示)正在加载多个版本的框架.如果是这种情况,该工具应建议解决方案.
完成后不要忘记从项目中删除 MvcDiagnostics.aspx.
Don't forget to delete MvcDiagnostics.aspx from your project when you are done.
这篇关于错误“'~/Views/Page/home.aspx' 中的视图必须派生自 ViewPage、ViewPage<TViewData>、ViewUserControl 或 ViewUserControl<TViewData>"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!