I want to show all my project on one page. but it give me a null refence everytime i use the code to show all project. But when i add .Take(6) it works :D i dont get it.
It worked earlier today. What do i do wrong ??
This one here it work with
var selection = Model.Content.Site().FirstChild("projekter").Children().Where(x => x.IsVisible()).OrderByDescending(x => x.CreateDate).Take(6);
But this one her i dont. I get a nul reference
var blogItems = Model.Content.Children<Projekt>();
The reason you're getting a null reference using Model.Content.Children<Projekt>() is because you're trying to return the children for the current page, instead of
returning all of the children of the Projekt document type.
If the current page doesn't have any children of type 'projekter', then you'll always return a null value.
Adapting your original solution (that works), you could try using the following line instead:
var blogItems = Model.Content.Site().FirstChild("projekter").Children();
It's a bit shorter and removes the additional logic that you're working solution has, so hopefully a happy medium!
Why does my code not work
I want to show all my project on one page. but it give me a null refence everytime i use the code to show all project. But when i add .Take(6) it works :D i dont get it. It worked earlier today. What do i do wrong ??
This one here it work with
But this one her i dont. I get a nul reference
Here is the code i want to have to work :D
The reason you're getting a null reference using
Model.Content.Children<Projekt>()
is because you're trying to return the children for the current page, instead of returning all of the children of the Projekt document type.If the current page doesn't have any children of type 'projekter', then you'll always return a null value.
Adapting your original solution (that works), you could try using the following line instead:
It's a bit shorter and removes the additional logic that you're working solution has, so hopefully a happy medium!
You might also want to look at the documentation on querying as well :)
Thanks for your help that work fine :D
is working on a reply...