CS0103:编辑现有且有效的代码文件时,当前上下文中不存在该名称

CS0103: The name does not exist in the current context while editing an existing and working code file

我的 ASP.Net MVC 项目需要帮助。这个项目 运行 很好,但是当我尝试进行一些更改时,出现此错误

CS0103 The name 'ASPxDocumentViewer1' does not exist in the current context 2_Reporting_FinIncomeStatement.aspx, BrokerOffice

我正在处理 3 个文件

FinIncomeStatement.aspx
FinIncomeStatement.aspx.cs
FinIncomeStatement.aspx.designer.cs

示例代码

In the FinIncomeStatement.aspx file

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" MaintainScrollPositionOnPostback="true" AutoEventWireup="true" CodeFile="FinIncomeStatement.aspx.cs" Inherits="BrokerOffice.Reporting.FinIncomeStatement" %>


<%@ Register Assembly="DevExpress.XtraReports.v15.2.Web, Version=15.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.XtraReports.Web" TagPrefix="dx" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div style="margin-left: 5%; margin-right: 10%; background: white" class="form-horizontal">

    </div>
    <dx:ASPxDocumentViewer ID="ASPxDocumentViewer1" runat="server" ReportTypeName="BrokerOffice.Reporting.XtraFinIncomeStatement" Theme="Moderno"></dx:ASPxDocumentViewer>
</asp:Content>

In the FinIncomeStatement.aspx.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BrokerOffice.Reporting
{
    public partial class FinIncomeStatement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Page_Init(object sender, EventArgs e)
        {

              XtraFinIncomeStatement report = new XtraFinIncomeStatement();


               ASPxDocumentViewer1.Report = report;
        }

    }
}

In the FinIncomeStatement.aspx.designer.cs file

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated. 
// </auto-generated>
//------------------------------------------------------------------------------

namespace BrokerOffice.Reporting {


    public partial class FinIncomeStatement {

        /// <summary>
        /// ASPxDocumentViewer1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::DevExpress.XtraReports.Web.ASPxDocumentViewer ASPxDocumentViewer1;
    }
}

现在我的文件夹中没有这个文件2_Reporting_FinIncomeStatement.aspx探险家。 VS 从哪里得到它?

  1. 我重启电脑好几次了
  2. 从我的项目中删除了 .vs 和 .git 文件
  3. 清理项目并重建项目
  4. 在我的 .aspx 表单中将 CodeBehind 重命名为 CodeFile 并返回
  5. 用vs2019和vs2015打开项目

如果我完全删除文件并添加一个新表单,然后复制并粘贴相同的代码,它就可以工作。

但是每当我想添加或编辑一些代码时,我无法继续删除文件并添加新文件。 我的问题是什么可能是额外的 2_Reporting_FinIncomeStatement.aspx 神秘形式的原因。如果我搜索整个解决方案,我找不到它,但我可以在此处找到它的标签

删除您的 aspx 文件的这一部分。

Inherits="BrokerOffice.Reporting.FinIncomeStatement"

因为您没有继承此页面上的任何内容。