使用带有Razor视图引擎的三元组时遇到一些麻烦.
我的模型有一个字符串属性.如果该字符串属性为null,我想在视图中呈现null.如果属性不为null,我希望它使用前导和尾随’来呈现属性值.
我怎样才能做到这一点?
更新:对不起,稍微改了一下问题.
解决方法
您应该只能使用标题建议的三元运算符:
@(string.IsNullOrEmpty(Model.Prop) ? "null" : "'" + Model.Prop + "'")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。