Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to cast object of type 'ASP._Page_Areas_Admin__ViewStart_cshtml' to type 'System.Web.WebPages.StartPage'

I created an area named "Admin".

In /Areas/Admin/Views/, I have _ViewStart.cshtml with this:

@{
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}

I'm getting the following error when I visit a page in /Admin/: Unable to cast object of type 'ASP._Page_Areas_Admin__ViewStart_cshtml' to type 'System.Web.WebPages.StartPage'.

I made the suggested changes from How do I use a common _ViewStart in areas?.

I have this in my web.config in the root, and the web.config at /Areas/Admin/Views/:

<configSections>
  <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  </sectionGroup>
</configSections>

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" />
    </namespaces>
  </pages>
</system.web.webPages.razor>

<appSettings>
  <add key="webpages:Version" value="1.0.0.0"/>
  <add key="webpages:Enabled" value="false" />
  <add key="ClientValidationEnabled" value="true"/>
  <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>

Anyone know what I'm doing wrong here?

EDIT: Don't know if this helps, but if I delete the code in _ViewStart.cshtml so that it's empty, I'm able to view the pages in /Admin without getting an error.

like image 314
Steven Avatar asked May 17 '11 02:05

Steven


1 Answers

_ViewStart.cshtml files can only be placed into a Views folder. The exception you are getting very strongly suggests that you have not placed the _ViewStart.cshtml inside the ~/Areas/Admin/Views/ folder (at the same level as the web.config).

Here's how a correct project structure should look like:

enter image description here

like image 169
Darin Dimitrov Avatar answered Sep 22 '22 06:09

Darin Dimitrov