我的一个 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/