-1

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.

Digbyswift
  • 10,310
  • 4
  • 38
  • 66
Arbejdsglæde
  • 13,670
  • 26
  • 78
  • 144

1 Answers1

3

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>
}
Dan Diplo
  • 25,076
  • 4
  • 67
  • 89
  • I'm not sure how this answer has been accepted, in Umbraco 7.1 (might not be the target version which OP was using), you cannot inherit anything when a model is used. Is this a new thing with Umbraco? (attached screenshot: http://i.imgur.com/v9ozlCX.png of using a model at the same time as inheriting) – Jamie Taylor Sep 04 '14 at 13:08
  • This works in 7.1 too. Your inherits should be the full path: `@inherits Umbraco.Web.Mvc.UmbracoTemplatePage` – Dan Diplo Sep 05 '14 at 09:05