Solved

if then in MVC

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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