views:

2924

answers:

2

I have a new ASP.NET MVC project (my first), and I had been running fine with 1 controller, view, and model. After I added a new controller and view, my first view started throwing this error message when I try to run the project:

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

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>

This is the entire contents of my Code Behind for that aspx page:

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

I'm not sure what changed in my app that is causing this. It seems like VS might be reading this as a webforms app instead of an MVC app maybe? Any ideas on where I should start to troubleshoot?

+5  A: 

I've had this happen before. Can't explain it. I ended up rebuilding the first view by creating it again and copying and pasting the markup. Also try shutting down VS and restarting.

Trevor de Koekkoek
I did exactly that, and now it works. No explanation as to why.
Mark Struzinski
Same problem, and did not expect this solution to work, but it did! In fact I just needed to close and restart studio then recompiled.
Vdex
A: 

This happened to me before too. It happened when I changed the name of the .aspx file after adding it to the project. Changing the name of your .aspx file does automatically change the names of your .axpx.cs and .axpx.designer.cs files, but it does not change any instance of the original name inside of your .aspx.cs file. You have to go in and change that manually. I was using VS 2005, so it may be different for newer versions.

Sean