It's to do with data type casting, I was using var and not casting the results was the problem if I recall. Today I would write it something like this.
using umbraco.NodeFactory;
List<Node> events =
@Model.NodeById(@pageId).Children.Where(x => x.NodeTypeAlias.Text == "Event").ToList();
Using .Where to list only a certain child doctype
So I have a page which has a few child pages of varying doctypes.
Im wanting to display some data from just the pages that have Room as the doctype.
After a little googling I found the below but im not getting anything displayed, no errors. Am I missing something?
Thanks
Hi Simon,
Try:
@Model.AncestorOrSelf(1).Children.Where("NodeTypeAlias==\"Room\"").FirstOrDefault()
I would prefer to use http://ucomponents.org/umapper/
Also, you can always debug it.
Regards,
mkariti
Hi mkariti
Im not sure on the correct usage of your suggested line
When Ive copied that into studio Im getting an error -
Umbraco.Web.Models.RenderModel' does not contain a definition for 'AncestorOrSelf'
Does anyone know why my original line isnt correct? Im a bit new to Razor and I really thought that would work!
Also just to add if I do the snippet without the .where it does return all the pagesm including the ones I dont want but I guess im half way there?
Are you using razor mvc? if so you ahould be able to do something like
Charlie. :)
Yes its Razor MVC :) And you know what, that looks familiar hmmm
Its moaning about <Umbraco.Core.Models.IPublishedContent,int,bool>' does not take 1 arguments however, any ideas?
FIXED IT WOOO my working line is now:
@foreach (var room in Model.Content.Children.Where(x => x.DocumentTypeAlias == "Room"))
{
Stuff
}
Changed the NodTypeAlias to DocumentTypeAlias and its happy now :)
Thanks both
yea sorry would be doc type alias :D. Glad you solved it. Charlie :)
Though I am using NodeTypeAlias still, I tried a slight tweak on Charlie's solution but it breaks.
This line works
but then I have to loop through with something like this, which works, but it's ugly
If I could use some variation of Charlie's solution above...something like this
Umbraco says
Thanks for any pointers you all may have.
-Roger
Hi Roger, Did you ever find a solution to your error?
Hi Leigh,
It's to do with data type casting, I was using var and not casting the results was the problem if I recall. Today I would write it something like this.
There is a good post here about using generics to achieve this if that's an option for you. http://stackoverflow.com/questions/21388447/lambda-expression-as-an-argument-to-a-dynamically-dispatched-operation
-Roger
is working on a reply...