我有具有2个局部视图的Layout,有2个模型。
@await Html.PartialAsync("~/Views/Account/Login.cshtml",null)
@await Html.PartialAsync("~/Views/Account/Register.cshtml",null)
但是布局的其他部分不起作用。错误
InvalidOperationException:传递给ViewDataDictionary的模型项的类型为'System.Collections.Generic.List`1 [App2.Models.Search]',但是此ViewDataDictionary实例需要类型为'App2.Models.ViewModels的模型项。 LoginModel'。
告诉我,如何解决?也许其他方式
InvalidOperationException:传递给ViewDataDictionary的模型项的类型为'System.Collections.Generic.List`1 [App2.Models.Search]',但是此ViewDataDictionary实例需要类型为'App2.Models.ViewModels的模型项。 LoginModel'。
您可以尝试将LoginModel
的实例而不是null
传递到局部视图,如下所示。
@await Html.PartialAsync("~/Views/Account/Login.cshtml", new LoginModel())