开发者

Shorthand if else with razor

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?


You need parentheses to use an expression:

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


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

@(myPosts != null ? (myPosts.Contains(item.ID) ? "Yes" : "No") : "Null")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜