ASP.NET MVC - 母版页和视图页的不同模型
我有一个强类型母版页,但我想对其某些子页面使用不同的类型。
例如,在母版页上...
<%@ Master ... Inherits="System.Web.Mvc.ViewMasterPage<MyWeb.Models.Client>" %>
客户端已经是一个复合对象,因此在某些子页面上我可以保持相同的模型并仅引用成员对象。 但在其他页面上,这样做没有意义,因为我正在处理不同的模型,例如处理客户模型的子页面。
我的母版页仍然需要客户端模型,但子视图将完全适用于不同的模型。 问题是,在控制器中,您只能将一个对象模型传递给视图。 有没有办法将一种模型传递给主人,并将不同的模型传递给视图? 谢谢!
I have a strongly typed master page, but I want to use a different type for some of it's child pages.
For example, on the master page...
<%@ Master ... Inherits="System.Web.Mvc.ViewMasterPage<MyWeb.Models.Client>" %>
Client is already a composite object, so on some of the child pages I can keep to the same model and just reference member objects. But on other pages, it won't make sense to do so as I am dealing with a different model, for example, a child page that deals with a Customer model.
My master page still needs the Client model, but the child views will work with different models entirely. The problem is, in a controller, there you can only pass one object model to the View. Is there any way to pass one model to the master and a different one to the view? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建层次结构并将基本模型传递到母版页,将子模型传递到视图。
这样,您的主视图将只能看到它自己的数据(在主模型类中可用),而您的视图将可以访问子模型类中可用的扩展信息。
很简单。
You can create an hierarchy and pass the base model to the master page and child models to your views.
This way, you master view will only see its own data (available in master model class) while you views will have access to the extended information available in child model classes.
Very simple.