c# - 部分观点的论证是错误的类型——这怎么可能?

标签 c# asp.net .net asp.net-mvc

我的一个 View (cshtml 文件)中有以下行:

@Html.Partial("_ProviderRatingWidget", Model.RatingInfo)

在我的实验室中,一切似乎都运行良好。但是在部署中,我们看到以下错误:

System.InvalidOperationException: The model item passed into the dictionary is of type 'ProviderContactInfo', but this dictionary requires a model item of type 'RatingCategorySummaryModel'.

Model 明确属于 ProviderContactInfo 类型,Model.RatingInfo 明确属于 RatingCategorySummaryModel 类型。那么这一行怎么能传递 ProviderContactInfo 类型呢?

谁能看到这条线可能产生该错误的任何可能情况?

编辑

哦,我应该指出,上面的行也是局部 View 。 (局部 View 正在加载另一个局部 View 。)这可能与问题有关。

最佳答案

我已验证如果您尝试传递的属性为空,则当前模型将被传递。你可以解决这个问题:

@Html.RenderPartial("_ProviderRatingWidget", new ViewDataDictionary(Model.RatingInfo));

希望对您有所帮助!

关于c# - 部分观点的论证是错误的类型——这怎么可能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19864903/

相关文章:

c# - 重试之前的任务操作 TPL

c# - Azure,ClosedXML : Build will NOT include DocumentFormat. OpenXML 在我的应用程序的 bin 文件夹中

c# - 为什么强制转换为 (int?) 有效而 (string?) 在 LINQ 查询中不起作用

c# - 查找重复的项目,然后选择日期与 currentDate 最接近的一项

c# - 协助重构 LINQ 方法

c# - 从动态添加的文本框获取值 asp.net c#

asp.net - Azure 示例网站图形无法正常工作

c# - 如何通过堆栈跟踪访问本地人? (模仿动态作用域)

c# - 在我自己的登录表单中使用 Windows 身份验证

.net - 如何让 System.Web.Optimization 包与 IIS 虚拟目录中的自定义文件夹一起使用?