最近将 dotnet core 1.0.1 更新到 1.1 和 MVC 中的 ViewComponent 开始失败,但出现以下异常:
InvalidOperationException: One or more errors occurred. (The model item passed into the ViewDataDictionary is of type 'App.Models.HomeViewModel', but this ViewDataDictionary instance requires a model item of type 'App.Components.LoginViewComponent'.)
Index.cshtml呈现LoginViewComponent:_
@model App.Models.HomeViewModel
<html>
@Component.InvokeAsync("LoginViewComponent")
</html>
视图/主页/Index.cshtml
ViewComponent LoginViewComponent/Default.cshtml只是一个显示其模型信息的类:
@model App.Components.LoginViewCompoent
<body>
<div>@Html.DisplayFor(v=>v.LoginName)</div>
</body>
视图/共享/组件/LoginViewComponent/Default.cshtml
当@model指令从Default.cshtml中删除时,它呈现良好。
ViewComponent 不是应该与包装它的父视图分离和不可知的吗?从异常看来,似乎需要在HomeViewModel类中声明LoginViewComponent ViewComponent才能呈现它。
在 asp.net core github 上找不到任何更改说明。
对此的评论和帮助将不胜感激。