The view '~/Views/Login/Login.aspx' must derive from ViewPage, ViewPage, ViewUserControl or ViewUserControl

前端 未结 2 966
梦谈多话
梦谈多话 2021-01-16 16:19

So I am getting this error on ASP.NET mvc2 solutions that used to work fine. I had to install Visual Studio 2012 and was running low on disk space, so had to manually uninst

相关标签:
2条回答
  • 2021-01-16 16:46

    It's been some time, but .. I stumbled across this question multiple times now, because I had the same error message. After getting my stuff together (not practicing ASP.NET MVC 5 that often) I realized that the CodeBehind-File WebForm.aspx.cs contains the Page_Load directive within the class of the WebForm itself:

    public partial class WebForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                // Your logic here
            }
        }
    }
    

    Your CodeBehind-File can be found within the (VS2017) Project Explorer (I called mine IndexForm instead of WebForm):

    Suggestions like "delete the CodeBehind-File" are solving the problem but might unintentionally cause new issues caused by this fix. Or you might just want to implement logic behind your WebForm, but can't because the file is deleted.

    This happens only because the auto-generated file is using System.Web.UI.Page instead deriving from System.Web.Mvc.ViewPage. So simply adjust your base class you inherit your WebForm from. Hopefully you will land here:

    public partial class WebForm : System.Web.Mvc.ViewPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                // Your logic here
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-16 17:02

    Well it seems like this problem can happen if something happenes with the installation of the .NET Framework 4.0. If you get this error try uninstalling anything you installed recently which might have altered the .NET framework installation.

    0 讨论(0)
提交回复
热议问题