Solved

if then in MVC

Posted on 2013-06-22
2
307 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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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