maryam
maryam

Reputation: 377

Partial views in ASP.NET MVC 3 (multi partial view into one view)

I want views several partial view into a one view. In fact, it is like a master form that also includes several sub-forms. How do I do this?

Upvotes: 2

Views: 3956

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

You could put this in a partial:

@Html.Partial("Partial1")
@Html.Partial("~/Views/Foo/Partial2")
@Html.Partial("Partial3")

and finally include this partial somewhere:

@Html.Partial("CombinedViewsPartial")

Upvotes: 4

GvS
GvS

Reputation: 52518

In your view, use this:

@Html.Partial("NameOfYourView")

@Html.Partial("../OtherViewFolder/NameOfPartialView", varToPassAsModel)

Or in a loop:

@foreach(var orderLine in model.OrderLines) {
   @Html.Partial("../OrderLine/Details", orderLine) @* Without executing another controller *@
   @Html.Action("Details", "OrderLine", new { lineNr = orderLine.LineNr, orderNr = orderLine.OrderNr }) @* Goes through controller *@
}

Upvotes: 2

Related Questions