Object Model Types in MVC2 using a strongly typed pageview task
I have a new converted MVC2 project working with MVC2 source code. I have done this conversation twice in the same solution.
I use strongly typed views on every page of the site and so far I have not had source related issues and have not developed with strongly typed views.
Now on one strongly typed view in particular, the shared parameter is not reflected in the Model property of that page.
Instead of a model of type T, I always have an object model of the type.
Code for a 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">
View Model:
public class ThingViewModel
{
public string Browser { get; set; }
}
I don't know what's going on here.
If I add a new view using the Add View Wizard, everything works fine, but on this existing page, I always get an object for my view model type.
I can get around this, just wondering what's going on here?
Is there something cached behind the scenes? Just curious what I am missing.
In this case, the controller passes a new ThingVingModel ().
source to share
You have to override the parser with a new one. Check the 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
<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>
source to share