Cut if another with a razor

I use this in my opinion and want it to display only "Yes" or "No", but its display is False?"yes":"No"

 @myPosts.Contains(item.ID)?"Yes":"No" 

What is wrong here?

+50
c # asp.net-mvc razor
Jan 02 '10 at 18:20
source share
2 answers

You need parentheses to express:

 @(myPosts.Contains(item.ID)?"Yes":"No") 
+93
Jan 02 '10 at 18:24
source share

You can even get a shorthand if inside another shorthand, if!

 @(myPosts != null ? (myPosts.Contains(item.ID) ? "Yes" : "No") : "Null") 
+7
Apr 09 '13 at 16:26
source share



All Articles