Umbraco How to read content items using ASP.NET MVC Partial View and Razor

StackOverflow https://stackoverflow.com/questions/17955953

  •  04-06-2022
  •  | 
  •  

Вопрос

I have some special document type in Umbraco and in content tree I have one item that contains sub-items with this document type. I don't want to use VS 2012. and I want to create some partial view for read this items. and create some html markup. I created, partial view via umbraco UI,

@inherits Umbraco.Web.Mvc.UmbracoViewPage<dynamic> 

How to read all item and subitems in my view just with Umbraco API ?

Thanks.

Это было полезно?

Решение

You should inherit from Umbraco.Web.Mvc.UmbracoTemplatePage in your partial view:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage

Then pass into your partial the current model:

@Html.Partial("MyPartialName", Model.Content)

Then in your partial you can just the API to get the children or whatever your query is:

@foreach (var node in Model.Children().Where(x => x.DocumentTypeAlias == "YourDocTypeAlias")
{
   <p>@node.Name</p>
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top