Asp.net mvc MVC模型在局部视图中转换,f__匿名类型6

Asp.net mvc MVC模型在局部视图中转换,f__匿名类型6,asp.net-mvc,razor,Asp.net Mvc,Razor,是否可以将模型强制转换为局部视图 @Html.Partial(Model.Partial, new { model = ((WarningPopupModel)CommonData.NotificationPopup.PopupModel) }) 这里的PopupModel是object类型,但保存了WarningPopupModel的一个实例,当我尝试时,这是我得到的错误 Additional information: The model item passed into the dicti

是否可以将模型强制转换为局部视图

@Html.Partial(Model.Partial, new { model =
((WarningPopupModel)CommonData.NotificationPopup.PopupModel) })
这里的PopupModel是object类型,但保存了WarningPopupModel的一个实例,当我尝试时,这是我得到的错误

Additional information: The model item passed into the dictionary is of type
'<>f__AnonymousType6`1[EmployeeKiosk.Models.WarningPopupModel]', 
but this dictionary requires a model item of type
'EmployeeKiosk.Models.WarningPopupModel'.
附加信息:传入字典的模型项的类型为
'f_uAnonymousType6'1[EmployeeKiosk.Models.WarningPopupModel],
但此词典需要类型为的模型项
“EmployeeKiosk.Models.WarningPopupModel”。
所以我真的需要理解“f__AnonymousType6”部分,知道我在这里有什么样的灵活性

背景

我想根据一些业务逻辑在视图中创建一个弹出窗口,这样控制器最终会将视图的名称(或者它可能是一个令牌)与一些模型一起传回

在视图中,我只需要一些能够在显示的部分视图之间切换的方法,部分视图将是剑道弹出窗口


谢谢

非常确定您应该能够将其更改为

@Html.Partial(Model.Partial, (WarningPopupModel)CommonData.NotificationPopup.PopupModel);

没有
new{model=…}
部分。

匿名类型部分指的是:
new{…}
-您正在传入一个匿名对象,它将您的模型作为名为
model
的属性包含在其中。您可能只想传入
(WarningPopupModel)CommonData.NotificationPopup.PopupModel
Argh!就这么简单,是的,成功了。我会在11分钟内接受这个答案:-)这是每个人最后都会做一次的MVC事情之一