传递到字典的模型产品类型“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‘

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

问题描述

我在我的一些建造这恼人的错误。

有在项目没有错误,因为如果我再次构建,那么问题就会消失。只有出现消息,当网站被部署到Windows 2008服务器。

我首先想到,这可能是临时文件的问题,但多数民众赞成并非如此。我部署构建到一个不同的网络和错误仍然出现。

在现场随机行为出现错误。大部分时间版本是好的,但每一个第三或第四的构建产生运行时错误。

我用建立在释放模式一WebdeploymentProject。视图是precompiled。

这不是<一个href=\"http://stackoverflow.com/questions/178194/in-asp-net-mvc-i-encounter-an-incorrect-type-error-when-rendering-a-page-with-the\">In ASP.NET MVC渲染我用正确类型的对象页面时遇到了不正确类型的错误,因为意见有完全不同的名字。

我如何调试这个问题,或者我如何能得到帮助呢?

下面是我的WebDeploymentProject

 &LT;! - 
      微软Visual Studio 2008的Web部署项目
      http://go.microsoft.com/fwlink/?LinkID=104956     - &GT;
    &LT;项目ToolsVersion =3.5DefaultTargets =生成的xmlns =htt​​p://schemas.microsoft.com/developer/msbuild/2003&GT;
      &LT;&的PropertyGroup GT;
        &lt;结构条件='$(配置)'==''&GT;调试和LT; /结构&gt;
        &LT;平台条件='$(平台)'==''&GT;&值为anycpu LT; /平台和GT;
        &LT;&的ProductVersion GT; 9.0.21022&LT; /&的ProductVersion GT;
        &LT; SchemaVersion&GT; 2.0&LT; / SchemaVersion&GT;
        &LT; ProjectGuid&GT; {E5E14CEB-0BCD-4203-9A5A-34ABA9C717EA}&LT; / ProjectGuid&GT;
        &LT; SourceWebPhysicalPath&GT; .. \\ B2CWeb&LT; / SourceWebPhysicalPath&GT;
        <SourceWebProject>{3E632DB6-6DB3-4BD0-8CCA-12DE67165B48}|B2CWeb\\B2CWeb.csproj</SourceWebProject>
        &LT; SourceWebVirtualPath&GT; /B2CWeb.csproj< / SourceWebVirtualPath&GT;
        &LT; TargetFrameworkVersion&GT;&V3.5 LT; / TargetFrameworkVersion&GT;
      &LT; /&的PropertyGroup GT;
      &LT;的PropertyGroup条件='$(配置)| $(平台)'=='调试|值为anycpu'&GT;
        &LT; D​​ebugSymbols&GT;真&LT; / DebugSymbols&GT;
        &LT; OutputPath方式&gt; \\调试和LT; / OutputPath&GT;
        &LT; EnableUpdateable&GT;假LT; / EnableUpdateable&GT;
        &LT; UseMerge&GT;真&LT; / UseMerge&GT;
        &LT; SingleAssemblyName&GT; B2CWeb_Build&LT; / SingleAssemblyName&GT;
      &LT; /&的PropertyGroup GT;
      &LT;的PropertyGroup条件='$(配置)| $(平台)'=='发布|值为anycpu'&GT;
        &LT; D​​ebugSymbols&GT;假LT; / DebugSymbols&GT;
        &LT; OutputPath&GT; .. \\ B2CWeb_Deploy \\&LT; / OutputPath&GT;
        &LT; EnableUpdateable&GT;假LT; / EnableUpdateable&GT;
        &LT; UseMerge&GT;真&LT; / UseMerge&GT;
        &LT; SingleAssemblyName&GT; B2C_Web&LT; / SingleAssemblyName&GT;
        &LT; ContentAssemblyName&GT;
        &LT; / ContentAssemblyName&GT;
        &LT; D​​eleteApp codeCompiledFiles&GT;假LT; / DeleteApp codeCompiledFiles&GT;
      &LT; /&的PropertyGroup GT;
      &LT;&的ItemGroup GT;
      &LT; /&的ItemGroup GT;
      &LT;导入项目=$(MSBuildExtensionsPath)\\微软\\ WebDeployment \\ 9.0 \\ Microsoft.WebDeployment.targets/&GT;
      &LT;! - 要修改你的构建过程中,添加以下里面的目标之一你的任务,并取消它。
           其它类似的扩展点的存在,看到Microsoft.WebDeployment.targets。
      &lt;目标名称=BeforeBuild&GT;
      &LT; /目标&GT;
      &lt;目标名称=BeforeMerge&GT;
      &LT; /目标&GT;
      &lt;目标名称=AfterMerge&GT;
      &LT; /目标&GT;
      &lt;目标名称=AfterBuild&GT;
      &LT; /目标&GT;
       - &GT;
    &LT; /项目&GT;

修改

几个月后,这个问题disapeared。我还没有现在已经1年以上的问题。我想,当没有人认为它的问题将再次发动袭击。

编辑2

...现在超过2年。我这样一个幸运的家伙!

编辑3

我刚才读<一个href=\"http://blogs.msdn.com/b/webdev/archive/2014/05/12/enabling-the-net-compiler-platform-roslyn-in-asp-net-applications.aspx\"相对=nofollow>在MSDN上的文章,这听起来像我有问题。我已经调试已禁用,但还是汇编是有时错误的。旧提供者的行为可能是问题。但是,这仅仅是猜测。


  包含HTML的长跨距没有服务器块

非常大的页面(例如小于%=%>),可以在编译调试启用,​​这将导致应用程序崩溃导致堆栈溢出。请注意,在我们的测试它采取一个页面这〜4倍,将已经产生的老提供商的类似问题的那么大,但是在这种情况下,它崩溃整个应用程序,而与老提供商,只不过没有违规页



解决方案

即使类型匹配,你可以当一个null被传递到局部视图这个错误,修复是调用的RenderPartial这样的: helper.RenderPartial(〜/查看/播放/ PlayerName.ascx,播放器,新的ViewDataDictionary()); 与空视图数据字典,也许在这里也适用?仅供参考,我发现这个解决方案在:

<一个href=\"http://stackoverflow.com/questions/650393/asp-net-mvc-renderpartial-with-null-model-gets-passed-the-wrong-type\">http://stackoverflow.com/questions/650393/asp-net-mvc-renderpartial-with-null-model-gets-passed-the-wrong-type

I have this annoying mistake in some of my builds.

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.

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.

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

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?

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}|B2CWeb\B2CWeb.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)\Microsoft\WebDeployment\v9.0\Microsoft.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>

EDIT

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.

EDIT 2

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

EDIT 3

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.

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

解决方案

Even if the types match, you can get this error when a null is passed to a partial view, the fix was to call RenderPartial like this: helper.RenderPartial("~/Views/Player/PlayerName.ascx", player,new ViewDataDictionary()); with an empty view data dictionary, perhaps that applies here as well? For reference I found this solution at:

http://stackoverflow.com/questions/650393/asp-net-mvc-renderpartial-with-null-model-gets-passed-the-wrong-type

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

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