Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I'm having a IPublishedContent query:
var announcement = Model.Content.DescendantsOrSelf().Where(x => x.DocumentTypeAlias == "AnnouncementItem").First();
however this line crashes when there are no announcement items.
I looked for some documentation here: http://our.umbraco.org/documentation/Reference/Mvc/querying but couldn't found anything.
Does anyone have an idea how to check for null in this query?
thanks for your help,
Anthony
Use the method FirstOrDefault and check if it is null then.
http://msdn.microsoft.com/en-us/library/bb340482(v=vs.110).aspx
Thanks a lot Marcio,
This worked:
var announcement = Model.Content.DescendantsOrSelf().Where(x => x.DocumentTypeAlias == "AnnouncementItem").FirstOrDefault();
Greetings,
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
how to check for null value with IPublishedContent
Hi,
I'm having a IPublishedContent query:
however this line crashes when there are no announcement items.
I looked for some documentation here: http://our.umbraco.org/documentation/Reference/Mvc/querying but couldn't found anything.
Does anyone have an idea how to check for null in this query?
thanks for your help,
Anthony
Hi,
Use the method FirstOrDefault and check if it is null then.
http://msdn.microsoft.com/en-us/library/bb340482(v=vs.110).aspx
Thanks a lot Marcio,
This worked:
Greetings,
Anthony
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.