60

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?

2

2 Answers 2

123

You need parentheses to use an expression:

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

You can even nest shorthand if inside of another shorthand if!

@(myPosts != null ? (myPosts.Contains(item.ID) ? "Yes" : "No") : "Null")
1
  • 1
    which is kind of use full when it comes to nullables: @(myObject.NullableBool != null ? (myObject.NullableBool ? "Yes" : "No") : "What would I know..")
    – Vegar
    Jun 17, 2016 at 13:42

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.