我可以从孩子局部视图访问父视图的模式? [英] Can I access the parent view's Model from a child partial view?

查看:102
本文介绍了我可以从孩子局部视图访问父视图的模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从一个孩子局部视图访问父视图的模式?我得到相互矛盾的信息,当我看到这件事。

Can I access the parent view's Model from a child partial view? I get conflicting information when I look this up.

如果是这样,任何人都可以指向我一个例子?

If so, can anyone point me at an example?

如果是这样,这将有助于使孩子Model对象父模型的属性?

And if so, would it help to make the child model object a property of the parent model?

推荐答案

No.If你所谈论的强烈结合使用的ViewModels的意见,那么你只能访问,如果你想要的东西,你传递给你的部分view.But模型要在局部视图,或者您可以使用ViewData字典任何其他视图中提供。

No.If you are talking about strongly binding the views with ViewModels then you can only access the model which you pass to your partial view.But if you want something to be available in partial view or any other view you can use ViewData dictionary.

您总是可以做和应该做的另一件事就是让你的视图模型以这样一种方式,使其迎合你的父视图,以及你的所有子视图。所以回答你的最后一个问题是你可以做儿童模特你的对象父模型的属性。

Other thing you can always do and should do is to make your view model in such a way so that it caters to your parent view as well as your all child views .So to answer your last question yes you can make child model object a property of your parent model.

在这里还有一点就是一定要保持你的域模型从中你要绑定到意见和结合它来看只是为了不使你的域模型的UI相关的更改视图模型是分开的。

Another point here is that make sure you keep your domain model separate from View model which you are going to bind to Views and not make UI related changes to your domain model for just the sake of binding it to view.

这篇关于我可以从孩子局部视图访问父视图的模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆