DarkVision
DarkVision

Reputation: 1423

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?

Upvotes: 0

Views: 1271

Answers (2)

Sanjeev Rai
Sanjeev Rai

Reputation: 6972

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").

Upvotes: 1

trailmax
trailmax

Reputation: 35106

You'll need to look at partial views: http://www.dotnetfunda.com/articles/article1831-how-to-create-partial-views-mvc-tutorial-number-10.aspx Also you can place your view file into Shared folder and reference it by a name: return View("commonView");

Upvotes: 1

Related Questions