最近更新的dotnet的核心1.0.1到1.1和ViewComponent在MVC開始與下面的異常失敗的渲染ViewComponent:出現InvalidOperationException在強類型的視圖
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假設是從包裝它的父視圖分離和不可知論?從例外情況看,它似乎需要聲明LoginViewComponent ViewComponent在HomeViewModel類爲了呈現它。
在asp.net core github上找不到任何有關此變化的註釋。
對此的評論和幫助將不勝感激。
沒有你UDPATE依賴關係? (mvc 1.1.0 etc ...) –
@ maua從火星是的,所有_Microsoft.AspNetCore。*參考_是在版本1.1.0 – danial
這看起來很奇怪:'@model App.Components.LoginViewCompoent',它是模型還是組件? –