JIbber4568
JIbber4568

Reputation: 839

List of objects to partial view using Knockout

I'm currently in the process of converting an application into Knockout. Currently there are a number of views that within them will loop round a list of objects within the model to then pass to a partialview to render that object.

<div>
    foreach (var item in Model.ListData) {
            Html.RenderPartial("~/Views/Shared/_ListPanel.cshtml", item);
            }
        }
</div>

In my knockout view model I have the same list of objects as an observable array. What would be the best way to pass each of them to the parital view and bind using knockout?

Upvotes: 0

Views: 441

Answers (1)

Domysee
Domysee

Reputation: 12846

Use a foreach binding to iterate through the elements:

<!-- ko foreach: Children -->
    //your partial view
<!-- /ko -->

Inside the partial view bind to the properties of the object as appropriate.

Upvotes: 3

Related Questions