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 there,
How can I check that a media item in null when I try to render it. I've tried various combinations the one below being one of them. I also tried the HasValue property. Any other suggestions?
Sean
@if (DynamicModel.GetProperty("imgBackground").Value.ToString() ==0)
{
<img src="@Umbraco.GetMediaUrl(DynamicModel.imgBackground, "uploadedFile")" alt="" />
}
Hi Sean,
I struggled myself quiet a lot with this. This post addresses this:
http://our.umbraco.org/forum/developers/razor/24951-Razor-best-practice-way-to-check-if-a-node-exists
Recently I used this code to see if an image for a member of a research group is available:
if(member.memberImage.ToString() != "") { image = member.memberImage.mediaItem.MemberImage.umbracoFile; }
Hope this helps,
Anthony
Hi Anthony,
That worked like a charm. Thanks very much.
Your welcome!
Glad I could help,
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Handling nulls for media items?
Hi there,
How can I check that a media item in null when I try to render it. I've tried various combinations the one below being one of them. I also tried the HasValue property. Any other suggestions?
Sean
@if (DynamicModel.GetProperty("imgBackground").Value.ToString() ==0)
{
<img src="@Umbraco.GetMediaUrl(DynamicModel.imgBackground, "uploadedFile")" alt="" />
}
Hi Sean,
I struggled myself quiet a lot with this. This post addresses this:
http://our.umbraco.org/forum/developers/razor/24951-Razor-best-practice-way-to-check-if-a-node-exists
Recently I used this code to see if an image for a member of a research group is available:
if(member.memberImage.ToString() != "")
{
image = member.memberImage.mediaItem.MemberImage.umbracoFile;
}
Hope this helps,
Anthony
Hi Anthony,
That worked like a charm. Thanks very much.
Sean
Hi Sean,
Your welcome!
Glad I could help,
Anthony
is working on a reply...