mvc3 razor 索引页面,包含两个带有差异的部分页面。页面模型
我的索引看起来像这样,页面模型接受对象列表
@model List<MyProject.Domain.Object>
@Html.Partial("PickDatePartial")
@Html.Partial("ObjectPartial", Model)
我的问题出在第一个部分页面内,因为该部分页面接受的不是列表,而是单个 @model MyProject.Domain.Object
我怎样才能实现这个,在当前情况下,索引页无法呈现,因为它期望接收对象列表。
先感谢您。
my index looks like this with page model which accepts list of objects
@model List<MyProject.Domain.Object>
@Html.Partial("PickDatePartial")
@Html.Partial("ObjectPartial", Model)
My problem is within this first partial page, cause this partial page accept not list but single @model MyProject.Domain.Object
How can I achive this, in this current situation index page cannot be rendered cause it expect to receive list of objects.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,您可以做的一件快速而肮脏的事情是将第一个对象传递给
PickDatePartial
但这不是很干净。我建议创建一个具有两个属性的视图模型,1)整个列表,2)由
PickDatePartial
绑定的属性:然后在控制器上的
Index
操作中:当然,您需要在
Index
视图上更改模型的类型。现在Index
视图如下所示:Well, one quick and dirty thing you could to is pass the first object to
PickDatePartial
This is however not very clean. I would recommend creating a view model with two properties, 1) the whole list, 2) the one to be bound by
PickDatePartial
:Then in your
Index
action on your controller:You'll need to change the type of the model on the
Index
view, of course. Now theIndex
view looks like this:如果“PickDatePartial”需要一个对象,并且您给它一个对象列表,那么它应该使用哪个对象?
由您决定要做什么。
您可以告诉它使用第一个对象:
或者,您可以为每个对象调用它:
可能性是无限的。
If "PickDatePartial" expects one object, and you give it a list of objects, what object should it use?
It is up to you to decide what to do.
You could tell it to use the first object:
or, you could call it for every object:
The possibilities are endless.