在MVC2对象模型类型使用强类型的视图页面的问题 [英] object Model types in MVC2 using strongly typed view pages problem

查看:134
本文介绍了在MVC2对象模型类型使用强类型的视图页面的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对MVC2源$ C ​​$ C运行新的转换MVC2项目。我在同一个解决方案做到了这一点谈话两次。

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.

现在在一个强类型的观点,特别是泛型参数没有被反映在该页面的Model属性。

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

而不必类型T的模型,我总是有类型的对象模型。

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

在code的非工作页:

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">

视图模型:

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

不知道怎么回事就在这里。

No clue whats going on here.

如果我使用Add View向导一切的伟大工程,新观点,但这个现有的网页我总是得到一个对象我的看法型号。

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.

控制器在这种情况下通过一个新ThingVingModel()

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

推荐答案

您应该重写用新的解析器。检查你的web.config文件中查看文件夹中。

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

它应该包含

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

而不是

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

这篇关于在MVC2对象模型类型使用强类型的视图页面的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆