views:

97

answers:

2

I've recently started using the Areas functionality of the Preview2 and it was working ok until I needed to return a Model to the view.

Controller:

public ActionResult ForgotPassword()
{
   return View(new PasswordViewModel());
}

View:

<%@ Import Namespace="Portal.Site.Areas.Logon.ViewModel"%>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PasswordViewModel>" %>

Nothing to difficult here, except i consistently get the following error.

Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage<PasswordViewModel>'.

This seems to happen to any view/controller within the areas section. If I remove the return model and add use the Dictionary, it works fine.

Now I am aware of issues regarding this, as the thread describes.

http://forums.asp.net/t/1378448.aspx

I would be interested to see if anyone thinks this is areas related? (Although in a clean basic project this works). Any suggestions on solutions? Is this a bug?

+2  A: 

This can be caused by not having a web.config in your views folder.

Example web.config pages settings:

<pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=************"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=************">
            <controls>
                <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
            </controls>
        </pages>
Andi
Thanks! Stupid how simple this was.
Pino
A: 

The problem might also be that it can't find the class PasswordViewModel because of a namespace difference. If you are using the default MVC project setup and the PasswordViewModel is in the Model folder, I believe the class name referenced in the page header should be web.model.PasswordViewModel.

Jeff Siver