简体   繁体   中英

How can 2 controllers communicate with 1 view in asp.net mvc

I would like one view to have access in 2 controllers. What I mean I have Controller A and Controller B and on the view i have 2 divs: Div A with content info from Controller A and Div b with content info from Controller B . Is it possible? Can someone give me a hint on how or show me a simple example?

您需要查看部分视图: http//www.dotnetfunda.com/articles/article1831-how-to-create-partial-views-mvc-tutorial-number-10.aspx您还可以放置视图文件进入共享文件夹并通过名称引用它: return View("commonView");

you can achieve this by using partial views.

Create a different partial views to show content from 2ND controllers render it on first view that has already data from 1st controller. you can render partial view using following razor syntax:

 @Html.Partial("name of partial view").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM