传递到字典中的模型项是‘mvc.Models.ModelA’类型,但这个字典需要一个‘mvc.Models.ModelB’类型的模型项 [英] The model item passed into the dictionary is of type ‘mvc.Models.ModelA’ but this dictionary requires a model item of type ‘mvc.Models.ModelB‘

查看:20
本文介绍了传递到字典中的模型项是‘mvc.Models.ModelA’类型,但这个字典需要一个‘mvc.Models.ModelB’类型的模型项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一些构建中,我有这个恼人的错误.

I have this annoying mistake in some of my builds.

项目中没有错误,因为如果我再次构建,那么问题就消失了.该消息仅在站点部署到 Windows 2008 Server 时出现.

There is no error in the project, because if I build again, then the problem disappears. The message only appears, when the site is deployed to a Windows 2008 Server.

我最初认为这可能是临时文件的问题,但事实并非如此.我将构建部署到不同的网站,但仍然出现错误.

I first thought that it might be an issue with temporary files, but thats not the case. I deployed the build to a different web and the error still appears.

该错误出现在网站的随机操作上.大多数情况下构建都可以,但每次第 3 次或第 4 次构建都会产生运行时错误.

The error appears on random actions of the site. Most of the time builds are ok, but each 3rd or 4th build produces runtime errors.

我在发布模式下使用 WebdeploymentProject 进行构建.视图是预编译的.

I build using a WebdeploymentProject in release mode. Views are precompiled.

这不是 在 ASP.NET MVC 中,我在呈现具有正确类型对象的页面时遇到错误类型错误,因为视图具有完全不同的名称.

It's not In ASP.NET MVC I encounter an incorrect type error when rendering a page with the correct typed object, because views have totally different names.

如何调试此问题或如何获得帮助?

How I can debug this problem or how I can get help for this?

这是我的 WebDeploymentProject

Here is my WebDeploymentProject

    <!-- 
      Microsoft Visual Studio 2008 Web Deployment Project 
      http://go.microsoft.com/fwlink/?LinkID=104956

    -->
    <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProductVersion>9.0.21022</ProductVersion>
        <SchemaVersion>2.0</SchemaVersion>
        <ProjectGuid>{E5E14CEB-0BCD-4203-9A5A-34ABA9C717EA}</ProjectGuid>
        <SourceWebPhysicalPath>..B2CWeb</SourceWebPhysicalPath>
        <SourceWebProject>{3E632DB6-6DB3-4BD0-8CCA-12DE67165B48}|B2CWebB2CWeb.csproj</SourceWebProject>
        <SourceWebVirtualPath>/B2CWeb.csproj</SourceWebVirtualPath>
        <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <DebugSymbols>true</DebugSymbols>
        <OutputPath>.Debug</OutputPath>
        <EnableUpdateable>false</EnableUpdateable>
        <UseMerge>true</UseMerge>
        <SingleAssemblyName>B2CWeb_Build</SingleAssemblyName>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <DebugSymbols>false</DebugSymbols>
        <OutputPath>..B2CWeb_Deploy</OutputPath>
        <EnableUpdateable>false</EnableUpdateable>
        <UseMerge>true</UseMerge>
        <SingleAssemblyName>B2C_Web</SingleAssemblyName>
        <ContentAssemblyName>
        </ContentAssemblyName>
        <DeleteAppCodeCompiledFiles>false</DeleteAppCodeCompiledFiles>
      </PropertyGroup>
      <ItemGroup>
      </ItemGroup>
      <Import Project="$(MSBuildExtensionsPath)MicrosoftWebDeploymentv9.0Microsoft.WebDeployment.targets" />
      <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
           Other similar extension points exist, see Microsoft.WebDeployment.targets.
      <Target Name="BeforeBuild">
      </Target>
      <Target Name="BeforeMerge">
      </Target>
      <Target Name="AfterMerge">
      </Target>
      <Target Name="AfterBuild">
      </Target>
      -->
    </Project>

编辑

几个月后,这个问题消失了.我现在已经1年多了没有问题.我想这个问题会在没人预料到的时候再次出现.

After some months this problem disapeared. I haven't had problems for over 1 year now. I guess the issue will strike again when nobody expects it.

编辑 2

... 2 年多了.我真是个幸运的家伙!

… for over 2 years now. I am such a lucky dude!

编辑 3

我刚刚阅读了 MSDN 上的一篇文章,这听起来像是我遇到的问题.我禁用了调试,但编译仍然有时是错误的".旧提供程序的行为可能是问题所在.但这只是猜测.

I just read an article on MSDN, and it sounds like the problem I had. I have debugging disabled, but still the compilation was "sometimes wrong". The behaviour of the old provider could be the issue. But this is just guessing.

包含长跨度 HTML 且没有服务器块(例如 <%= %>)的非常大的页面会在启用调试编译时导致堆栈溢出,从而导致应用程序崩溃.请注意,在我们的测试中,它采用了一个大约 4 倍大的页面,这会在旧提供程序中产生类似问题,但在这种情况下,它会使整个应用程序崩溃,而对于旧提供程序,它只会使违规页面失败

Very large pages containing long spans of HTML with no server blocks (e.g. <%= %>) can cause a stack overflow when debug compilation is enabled that will crash the application. Note that in our testing it’s taken a page that’s ~4x as large one that would’ve produced a similar issue in the old provider, but in this case it crashes the entire application, whereas with the old provider it just fails the offending page

推荐答案

即使类型匹配,当将 null 传递给局部视图时,您也会收到此错误.

Even if the types match, you can get this error when a null is passed to a partial view.

您可以通过使用空的 ViewDataDictionary 调用 RenderPartial 来解决此问题,如下所示:

You can fix this by calling RenderPartial with an empty ViewDataDictionary like this:

helper.RenderPartial("~/Views/Player/PlayerName.ascx", player, new ViewDataDictionary());

作为参考,我在以下位置找到了这个解决方案:
使用空模型的renderpartial被错误地传递输入

For reference, I found this solution at:
renderpartial with null model gets passed the wrong type

这篇关于传递到字典中的模型项是‘mvc.Models.ModelA’类型,但这个字典需要一个‘mvc.Models.ModelB’类型的模型项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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