我有一个新的 ASP.NET MVC 项目(我的第一个),并且我使用 1 个 Controller 、 View 和模型运行良好。添加新的 Controller 和 View 后,当我尝试运行项目时,我的第一个 View 开始抛出此错误消息:
描述:解析服务此请求所需的资源时发生错误。请查看以下特定解析错误详细信息并适当修改您的源文件。
Parser Error Message: 'PeopleManagement.Web.Views.Search.Search' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Source Error:
Line 1: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Master.Master" AutoEventWireup="true" CodeBehind="Search.aspx.cs" Inherits="PeopleManagement.Web.Views.Search.Search" %>
Line 2: <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
Line 3: </asp:Content>
这是我的该 aspx 页面的代码隐藏的全部内容:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace PeopleManagement.Web.Views.Search
{
public partial class Search : ViewPage
{
}
}
我不确定我的应用程序中发生了什么变化导致了这种情况。看起来 VS 可能会将其视为 Webforms 应用程序而不是 MVC 应用程序?关于我应该从哪里开始排除故障有什么想法吗?
最佳答案
我以前也遇到过这种情况。无法解释它。我最终通过再次创建第一个 View 并复制和粘贴标记来重建它。也可以尝试关闭 VS 并重新启动。
关于ASP.NET MVC 错误 : Page is not allowed here because it does not extend class 'System.Web.Page' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/381008/