Solved

if then in MVC

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now