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

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 uninstall some Visual Studio 2010 functionalities which didn't seem to be completely necessary at the moment. Now whenever I try to debug an application which targets the 4.0 .NET framework I get this error. I tried re-installing Visual Studio and the .net framework, but it keeps kappening. I don't know what to do.

Also, i tried what's stated in this question (Getting the error "The view at '~/Views/Page/home.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>") but couldn't put the answer marked as correct to work. Please help!

Answers


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
        }
    }
}

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.


Need Your Help

What's the best way to store the bible in SQL?

sql mysql database-design

What I'm looking for is a breakdown of table names w/ corresponding fields/types.