简体   繁体   English

在MVC中的同一页面上渲染两个Controller / Views

[英]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.

相关问题 Asp.net核心MVC两个列表,相同的模型,相同的控制器,两个具有相同模型问题的局部视图 - Asp.net core MVC two lists, same model, same controller, two partial views with same model issue 在同一控制器中的两个ActionResult之间传递数据,从而在ASP.NET MVC中呈现不同的视图 - Passing data between two ActionResults in the same controller rendering different views in asp.net mvc 返回ASP.NET MVC中不同视图的同一个控制器 - Return different views same controller in ASP.NET MVC 如何在同一页面上呈现两个菜单? - How to render two menus on same page? 从MVC中的两个局部视图获取控制器中的值 - Get values in controller from two partial views in MVC 控制器呈现所有局部视图 - Controller to render all Partial Views 将两个视图合二为一,针对相同的控制器操作返回两个视图 - Combining two views in one vs returning two views for same controller action 使用MVC在同一页面上的多个部分视图和模型绑定实例 - Multiple instances of partial views and model binding on same page with MVC 在MVC控制器中,相同的string.replace()具有两种不同的含义 - same string.replace() given two different meanings in MVC controller ASP.NET MVC 4 - 控制器结束后重定向到同一页面 - ASP.NET MVC 4 - Redirect to the same page after controller ends
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM