I'm starting my first umbraco project and have my first MVC views working fine. I have a simple controller action in which I would like to retrieve the children of the current item. My action looks like this:
var posts = CurrentPage.Children.Where(x=> ????)
I have been searching for quite a while now but can't seem to find anything explaining how to only load children that were published. There doesn't seem to be a property or method such as IsPublished. I have tried several different ways of filtering the children like
var posts = CurrentPage.Children.Where(x=> !x.IsDraft)
But I always get all children (I have two published test items and 2 not published items), whether they're published or not. Any ideas or suggestions on how to solve this?
CurrentPage.Children should only return published content, but default, built-in. Non-published content are not returned to views (unless previewing). So... you should not need a filter at all.
Thanks for pointing me into the right direction it was preview mode which was causing all items to be returned! With preview mode off, it all works as expected :)
Getting published children of current page
Hi,
I'm starting my first umbraco project and have my first MVC views working fine. I have a simple controller action in which I would like to retrieve the children of the current item. My action looks like this:
I have been searching for quite a while now but can't seem to find anything explaining how to only load children that were published. There doesn't seem to be a property or method such as IsPublished. I have tried several different ways of filtering the children like
But I always get all children (I have two published test items and 2 not published items), whether they're published or not. Any ideas or suggestions on how to solve this?
Thanks Ben
In case anyone is looking for an answer to this, I think I worked it out:
This seems to give me only the published items.
CurrentPage.Children should only return published content, but default, built-in. Non-published content are not returned to views (unless previewing). So... you should not need a filter at all.
Does that make sense?
Hi Stephen,
Thanks for pointing me into the right direction it was preview mode which was causing all items to be returned! With preview mode off, it all works as expected :)
Thank you!
is working on a reply...