InfoLearner
InfoLearner

Reputation: 15598

MVc3 How to combine two views to create one large view?

Is it possible to combine two views one after the other. one rendered in one div and the other rendered in the other div?

Upvotes: 0

Views: 2296

Answers (2)

scartag
scartag

Reputation: 17680

Yes you can.

You can render them as partial views (depending on what sort of markup they have .. you don't want to have multiple root html tags)

<div>@Html.Partial("View1")</div>

<div>@Html.Partial("View2")</div>

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

Yes, make those views partial and then use the Html.Partial helper to include them:

<div>
    @Html.Partial("_view1")
</div>

<div>
    @Html.Partial("_view2")
</div>

or using editor/display templates:

<div>
    @Html.DisplayFor(x => x.Foo)
</div>

<div>
    @Html.DisplayFor(x => x.Bar)
</div>

Upvotes: 5

Related Questions