开发者

Shorthand if else with razor

开发者 https://www.devze.com 2023-02-02 06:40 出处:网络
Im using this in my view and开发者_开发问答 want it to display only \"Yes\" or \"No\" but its displaying False?\"yes\":\"No\"

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

精彩评论

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