C# 传入字典的模型项的类型为‘;mvc.Models.ModelA’;但本词典需要类型为‘;mvc.Models.modelbandx2018;
在我的一些构建中,我犯了这个恼人的错误 项目中没有错误,因为如果我再次构建,那么问题就会消失。此消息仅在站点部署到Windows 2008服务器时显示 我最初认为这可能是临时文件的问题,但事实并非如此。我将构建部署到另一个web,错误仍然出现 该错误出现在站点的随机操作上。大多数时候构建都是正常的,但是每第三次或第四次构建都会产生运行时错误 我在发布模式下使用WebdeploymentProject进行构建。视图是预编译的 不是,因为视图有完全不同的名称 如何调试此问题,或者如何获得帮助 这是我的WebDeploymentProjectC# 传入字典的模型项的类型为‘;mvc.Models.ModelA’;但本词典需要类型为‘;mvc.Models.modelbandx2018;,c#,asp.net,.net,asp.net-mvc,build,C#,Asp.net,.net,Asp.net Mvc,Build,在我的一些构建中,我犯了这个恼人的错误 项目中没有错误,因为如果我再次构建,那么问题就会消失。此消息仅在站点部署到Windows 2008服务器时显示 我最初认为这可能是临时文件的问题,但事实并非如此。我将构建部署到另一个web,错误仍然出现 该错误出现在站点的随机操作上。大多数时候构建都是正常的,但是每第三次或第四次构建都会产生运行时错误 我在发布模式下使用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>
调试
任意CPU
9.0.21022
2
{E5E14CEB-0BCD-4203-9A5A-34ABA9C717EA}
..\B2CWeb
{3E632DB6-6DB3-4BD0-8CCA-12DE67165B48}B2CWeb\B2CWeb.csproj
/B2CWeb.csproj
v3.5
真的
.\Debug
假的
真的
B2CWeb_构建
假的
..\B2CWeb_部署\
假的
真的
B2C_网站
假的
编辑
几个月后,这个问题消失了。我已经一年多没有问题了。我想这个问题会在没有人预料到的时候再次出现
编辑2
…已经两年多了。我真是个幸运的家伙
编辑3
我刚读过,听起来像是我遇到的问题。我禁用了调试功能,但编译仍然“有时出错”。老供应商的行为可能是一个问题。但这只是猜测
当启用调试编译时,包含长跨距HTML且没有服务器块(例如)的超大页面可能会导致堆栈溢出,从而导致应用程序崩溃。请注意,在我们的测试中,它使用了一个约4倍于旧提供程序的页面,该页面可能会在旧提供程序中产生类似问题,但在本例中,它会使整个应用程序崩溃,而在旧提供程序中,它只会使有问题的页面失败
构建是否触发任何警告或错误 您是否正确设置了依赖项?视图取决于型号。Build通过查看指定的依赖项来确定编译的顺序。如果你改变了一个模型,并且视图在模型出现问题之前就被编译了
如果不编译视图,这会消失吗 您的视图是否继承了
System.Web.Mvc.ViewPage
或System.Web.Mvc.ViewPage
其中T是您的模型?您是否绝对确定这与传递给视图的数据无关?您是否每次都执行完全重建
发生这些错误的原因通常是,当传递给局部视图的视图模型为空时,局部视图尝试使用传递给ViewPage的视图模型。我知道你是在暗示这个错误是由构建过程引起的,但我不知道这怎么可能。
是否部署的站点使用的数据库与您在开发机器上运行的站点不同,并且该数据库中的数据(或缺少数据)可能是问题的原因?此错误可能会发生(并且确实会发生)控制器操作方法提供给视图的数据与视图期望的数据类型不匹配时。这通常不会显示为生成错误,即使使用预编译视图也是如此
例如,如果我有一个方法
public ActionResult Create()
{
// Do something
return View(new CustomerCreateViewModel());
}
…和具有页面属性的创建视图
<%@ Page ... Inherits="System.Web.Mvc.ViewPage<CustomerDetailsViewModel>" %>
…这将编译和生成而不会出错。但是,当我调用Create操作时,我会看到一个黄色屏幕,因为Create操作方法抛出一种类型的数据,而视图需要另一种类型的数据。您可能需要验证您的类型是否匹配…即使类型匹配,当向局部视图传递null时也会出现此错误 您可以通过使用空的
ViewDataDictionary
调用RenderPartial
来解决此问题,如下所示:
helper.RenderPartial("~/Views/Player/PlayerName.ascx", player, new ViewDataDictionary());
作为参考,我在:在从视图中将模型分配给usercontrol之前,请在模型/实体的构造函数中实例化该特定对象 例如:
public class MainEntity
{
public SubEntity AssociatedEntity;
public MainEntity()
{
// This is where the instantiation happen.
AssociatedEntity = new SubEntity();
}
}
public class SubEntity
{
public string property1;
}
您的查看页面:
<%@ Page Title="" Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<MyNamespace.Models.MainEntity>" %>
....
<%Html.RenderPartial("ucMyUserControl",Model.AssociatedEntity);
....
....
....
m、 房地产1);
ASP.NET MVC部分
传递了空模型
@Html.Partial("PartialView", model: Model)
如果您有一个覆盖视图文件夹,其中存在多个同名分区(一个覆盖另一个同名分区),请确保更新每个视图上的模型类型,否则您可能会收到此错误。我收到以下错误消息 传递到字典中的模型项的类型为 'System.Linq.Enumerable+WhereSelectListIterator2[MyProject.Models.A,MyProject.Models.B], 但此词典需要类型为的模型项 'System.Collections.Generic.List1[MyProject.Models.B]' 使用以下代码
IEnumerable<B> list_B;
...
IEnumerable<A> list_A = Repo.GetListOfType_A();
list_B = list_A.Select(x => new B { Number = x.Number, Name = x.Name });
...
return View(list_B);
希望它能帮助其他人对我来说,这是由我上下文中一个愚蠢的剪切粘贴错误造成的。我的联系人索引中出现了此错误
public DbSet<Customer> Customer { get; set; }
public DbSet<Customer> Contact { get; set; }
// Note this ^^^^^^^^ should have been Contact
公共数据库集客户{get;set;}
公共数据库集联系人{get;set;}
//请注意,此^^^^^^^^^^^^^^^本应为联系人
它编译的很好,但是在尝试渲染视图时给了我错误
(将此添加为其他内容,供未来寻求解决方案的人尝试。)我在使用Episerver时遇到此错误。我只是将控制器中的return语句从
返回视图()代码>
到
返回PartialView()<
IEnumerable<B> list_B;
...
IEnumerable<A>list_A = Repo.GetListOfType_A();
list_B = list_A.Select(x => new B { Number = x.Number, Name = x.Name }).ToList(); // here
...
return View(list_B);
public DbSet<Customer> Customer { get; set; }
public DbSet<Customer> Contact { get; set; }
// Note this ^^^^^^^^ should have been Contact