[英]Render two Controller/Views on the same page in MVC
Here's my scenario: 这是我的情景:
I need to create a page such that I have a view containing a DropDownList, then another (partial?) view beneath it that changes depending on what was selected in the DropDownList. 我需要创建一个页面,使得我有一个包含DropDownList的视图,然后在它下面的另一个(部分?)视图根据DropDownList中选择的内容而改变。 I know how to code the DropDownList and make it work with the controllers, but I'm pretty stumped on how to achieve my goal. 我知道如何编写DropDownList并使其与控制器一起工作,但我对如何实现我的目标感到非常难过。
The view that will change based on the DropDown has its own controller with CRUD operations (they contain grids). 基于DropDown更改的视图具有自己的具有CRUD操作的控制器(它们包含网格)。 I should add that i'm using a shared view that contains a sort of template for a grid. 我应该补充一点,我正在使用包含一种网格模板的共享视图。 There's lots of grids, but one view, and a controller for each grid. 有很多网格,但有一个视图,每个网格都有一个控制器。 So I can't just call in the view as a partial view, as it would have no data. 所以我不能只在视图中调用部分视图,因为它没有数据。 I'm essentially needing to call the controller for each grid, which then renders the view containing the grid. 我基本上需要为每个网格调用控制器,然后渲染包含网格的视图。
So how can I do this? 那我该怎么做呢?
you can use partial views to render your views, hence you can use Ajax to update the contents of any element or part of the rendered views dynamically. 您可以使用部分视图来呈现视图,因此您可以使用Ajax动态更新任何元素或部分渲染视图的内容。
you may use jquery to get the selected item value from the drop down list 您可以使用jquery从下拉列表中获取所选项目值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.