Sonja
Sonja

Reputation: 595

getting a list in MVC from Umbraco

I have Umbraco Document types MyContent and MyContentList. MyContentList has a list view of MyContent. In the partial View I have

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.MyContentList>
    @using ContentModels = Umbraco.Web.PublishedContentModels;

    @{
        Layout = "";
    }

    @Html.Partial("~/Views/Partials/MyView.cshtml",
     new MyProject.Models.MyContentList()
     {
         Target = @Umbraco.Field("ContentTarget").ToString(),
         Items = ???
     }

How do I get the list of items from Umbraco and pass it in my MVC?

Thanks

Upvotes: 0

Views: 261

Answers (1)

Robert Foster
Robert Foster

Reputation: 2316

Make sure you've loaded the Umbraco.Web namespace so the extension method can be used:

@using Umbraco.Web

Then you can try something like the following:

@foreach(var item in Model.Content.Children<ContentModels.MyContent>()){
// do something here
}

Also review the documentation on our.umbraco.com here:

https://our.umbraco.com/documentation/Reference/Querying/IPublishedContent/Collections

Upvotes: 1

Related Questions