?
Solved

if then in MVC

Posted on 2013-06-22
2
Medium Priority
?
313 Views
Last Modified: 2013-06-23
Hi,

I need to say if the item.ImageName is null or empty display the default image.

not sure what I am doing wrong.

Here's my code.

Thanks,

<img src="@Url.Content("~/Content/UploadedImages/" + String.IsNullOrEmpty(item.ImageName) ? "NO-IMAGE.png" : item.ImageName)" />

I want to do this
if item.ImageName is empty then display the no-image.png otherwise display the image name.
0
Comment
Question by:lulu50
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39268788
The string concatenation operator has a higher precedence than the ternay opartor does. Try using parentheses.

<img src="@Url.Content("~/Content/UploadedImages/" + (String.IsNullOrEmpty(item.ImageName) ? "NO-IMAGE.png" : item.ImageName))" />

Open in new window


http://msdn.microsoft.com/en-us/library/6a71f45d(v=vs.71).aspx
0
 

Author Closing Comment

by:lulu50
ID: 39268997
Thank you
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question