[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

if then in MVC

Posted on 2013-06-22
2
Medium Priority
?
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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