2

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?

2 Answers 2

4

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")
Sign up to request clarification or add additional context in comments.

Comments

2

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 *@
}

1 Comment

Hi Maryam, Please select the answer that helped you to solve your problem or at least explain how your problem was solved. By doing this you respect the person who helped you and also you help the other website users to learn more from your experience. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.