【问题标题】:Change ViewModel of some views in ASP.NET MVC causing error. How to fix?更改 ASP.NET MVC 中某些视图的 ViewModel 导致错误。怎么修?
【发布时间】:2016-03-30 15:10:00
【问题描述】:

有一个名为 HomeVM 的 ViewModel 有 7 个模型。我添加了一个名为 NewsVM 的新 ViewModel,并在 HomeVM 中剪切了 3 个模型并粘贴到 NewsVM 中。 我将所有内容都更改为新的 ViewModel,但出现此错误:

The model item passed into the dictionary is of type 'NP1.ViewModels.NewsVM', but this dictionary requires a model item of type 'NP1.ViewModels.HomeVM'.

感谢您的帮助。

【问题讨论】:

    标签: asp.net-mvc razor model asp.net-mvc-5 viewmodel


    【解决方案1】:

    确保您也更新您的视图:

    @model NP1.ViewModels.NewsVM
    

    【讨论】:

    • 我确定我改变了它:/
    • 也许您忘记在从主视图调用的某些局部视图中更改它。这个错误意味着你仍然有一些使用旧的@model 的视图。
    • 谢谢你亲爱的,你的权利我使用了@model NP1.ViewModels.HomeVM的布局。我应该为这个视图创建一个新的布局?!还是有其他解决方案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 2021-07-29
    • 2014-07-12
    • 2017-01-12
    • 2018-03-22
    • 1970-01-01
    相关资源
    最近更新 更多