Plantain Yao
Plantain Yao

Reputation: 401

How to return two partial views in asp.net mvc?

for example, in a Action, I get data and it will be shown in two different place, so I create two partial views, ViewA and ViewB. So the question is: how to return partial view ViewA and ViewB in the Action?

Upvotes: 1

Views: 4668

Answers (1)

ALM
ALM

Reputation: 11

If I understood your question correctly ...

Firstly, you can't return multiple views from a action since there can't be multiple return from a method. So to address your issue, create a model 'MODEL' with subclasses 'MODELA' and 'MODELB' in it catering the models for ViewA and ViewB. Create a view 'MainView', render the partial views ViewA and ViewB in 'MainView' using @Html.Partial. While rendering viewA and viewB, pass @Model.MODELA and @Model.MODELB respectively.

Upvotes: 1

Related Questions