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
I've been trying to get my head around this and getting nuts trying. ;)
I have a mediaitem that gets filled with DAMP, and am trying to check whether it exists using razor.
To do this, I tried two different ways, but none of them worked.
The first one I tried was:
if (currentPage.largeBanner.mediaItem != null)
That didn't do a thing, the error remains, which is logical in a way, as the xml contains only an empty CDATA, which is a string and no XML
Then I tried:
if (currentPage.largeBanner != "")
This works, when there is in fact no mediaitem present. However, that one won't work when there actually IS one present.
Anyone got the golden tip for me? The thing I overlooked?
Thanks in advance!
Hi hopefully this helps
instead of using
if (Model.largeBanner != "")
you can try
if (Model.largeBanner is int)
this will make sure that the dynamic type returned is of type int which means that the property is assigned and pointing to a mediaID
Casting first to a string and then check if the string is not empty seems to work also.But maybe this causes some overhead. Not sure about that.
if (currentPage.largeBanner.ToString() != "")
Yep didn't think of that, that would be great as well :)Alright have a great day glenn.
Unfortunately, that didn't solve it either. Appearantly when it has a banner, it has a completely different structure from when it doesn't have a banner.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Check if mediaitem exists
I've been trying to get my head around this and getting nuts trying. ;)
I have a mediaitem that gets filled with DAMP, and am trying to check whether it exists using razor.
To do this, I tried two different ways, but none of them worked.
The first one I tried was:
That didn't do a thing, the error remains, which is logical in a way, as the xml contains only an empty CDATA, which is a string and no XML
Then I tried:
This works, when there is in fact no mediaitem present. However, that one won't work when there actually IS one present.
Anyone got the golden tip for me? The thing I overlooked?
Thanks in advance!
Hi hopefully this helps
instead of using
if (Model.largeBanner != "")
you can try
if (Model.largeBanner is int)
this will make sure that the dynamic type returned is of type int which means that the property is assigned and pointing to a mediaID
Casting first to a string and then check if the string is not empty seems to work also.
But maybe this causes some overhead. Not sure about that.
Yep didn't think of that, that would be great as well :)
Alright have a great day glenn.
Unfortunately, that didn't solve it either. Appearantly when it has a banner, it has a completely different structure from when it doesn't have a banner.
is working on a reply...