与许多控制器相同的视图 [英] Same view with many controllers

查看:77
本文介绍了与许多控制器相同的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用很多控制器来控制一个视图。(这个视图处理三个数据库),

是可能的,

非常感谢。



我尝试了什么:



仍然我只有查看所以我需要说明。

Can we use many controllers to control one view.(this view deals with three data bases),
is t possible,
many thanks.

What I have tried:

still i have only view so i need instructions.

推荐答案

你可以在至少2个组合中将多个控制器绑定到1个视图



1)使用AJAX你可以加载部分视图(它们在自己的控制器中与自己的动作相关联......或者可以是同一个控制器)。这些部分视图被加载到主视图中,例如index.cshtml



2)您可以使用一个视图和许多不同的控制器在传统请求中返回该视图方式。这里唯一的事情是,如果你使用强类型视图,你将不得不在所有3个控制器中使用相同的模型。你最终可能会在这里使用ViewBag(或类似的东西)。



可能还有更多,这些是我见过的常见的。我主要使用选项1.



现在如果你开始处理这个问题而陷入困境,请随时回过头来清楚解释一下你的问题和一些相关的代码样品,我相信有人会很乐意为您提供帮助。
You can have multiple controllers tied to 1 view in at least 2 combinatins

1) Using AJAX you can load partial views (which are tied to their own actions in their own controller...or could be same controller). Those partial views are loaded into a primary view, for example index.cshtml

2) You can use one view and many different controllers that return that view in the traditional request manner. The only thing here is that if you used a strongly typed view your going to have to use the same model in all 3 controllers. You will probably end up using ViewBag here (or something like that).

There may be more, these are the common ones i've seen. I use option 1 primarily.

Now if you start working on this and get stuck somewhere, feel free to come back with a clear explanation of your issue and some relevant code samples and I am sure someone will be happy to help you.


这篇关于与许多控制器相同的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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