views:

1177

answers:

1

I have a new converted MVC2 project running against the MVC2 source code. I have done this conversation twice on the same solution.

I use strongly typed views on every page of the site and so far I haven't had any issues running against the source nor developing with strongly typed views.

Now on one strongly typed view in particular the generic parameter is not being reflected in the Model property of that page.

Instead of having a Model of type T I always have a Model of type object.

The code for the non-working page:

<%@Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ThingViewModel>" %>
<%@ Import Namespace="SProject.Web"%>

<asp:Content ID="Content1" ContentPlaceHolderID="PageTitleContentPlaceHolder" runat="server">
    <h2>Add Encounter <%= ViewData.Model.Browser %></h2>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="SidebarContentPlaceHolder" runat="server">

The view model:

public class ThingViewModel
{
    public string Browser { get; set; }
}

No clue whats going on here.

If I add a new View using the Add View wizard everything works great but this existing page I always get an object for my view model type.

I can work around this, just wondering whats happening here?

Is something cached behind the scenes? Just curious what I'm missing.

The controller is passing a new ThingVingModel() in this case.

+1  A: 

You should override the parser with the new one. Check your web.config file inside the Views folder.

it should contain

<pages
    validateRequest="false"
    pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    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=31BF3856AD364E35">
  <controls>
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
  </controls>
</pages>

instead of

 <pages
    validateRequest="false"
    pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <controls>
    <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
  </controls>
</pages>
dip_the_coder
There is also some info here:http://weblogs.asp.net/leftslipper/archive/2009/10/19/migrating-asp-net-mvc-1-0-applications-to-asp-net-mvc-2.aspx
dip_the_coder