Partial views in ASP.NET MVC 3 (multi partial view into one view)
I want views several partial vi开发者_Go百科ew into a one view. In fact, it is like a master form that also includes several sub-forms. How do I do this?
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")
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 *@
}
精彩评论