Shorthand if else with razor
C#asp.net MvcRazorC# Problem Overview
Im using this in my view and want it to display only "Yes" or "No"
but its displaying False?"yes":"No"
@myPosts.Contains(item.ID)?"Yes":"No"
Whats wrong here?
C# Solutions
Solution 1 - C#
You need parentheses to use an expression:
@(myPosts.Contains(item.ID)?"Yes":"No")
Solution 2 - C#
You can even nest shorthand if inside of another shorthand if!
@(myPosts != null ? (myPosts.Contains(item.ID) ? "Yes" : "No") : "Null")