帮助 c# 和 bool 在 asp.net mvc 上 [英] Help with c# and bool on asp.net mvc
本文介绍了帮助 c# 和 bool 在 asp.net mvc 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据值打印出是"或否"的最佳方式是什么
Whats the best way to print out "Yes" or "No" depending on a value
在我看来我想打印出来
Model.isStudent
Model.isStudent
我不想要 True 或 False,我想要 Yes 或 No.... 我必须写 if else 语句吗?
and I dont want True or False, I want Yes or No.... do I Have to write if else statement?
推荐答案
写一个辅助方法:
public static class MyExtensions
{
public static string FormatBool(this HtmlHelper html, bool value)
{
return html.Encode(value ? "Yes" : "No");
}
}
并像这样使用它:
<%= Html.FormatBool(Model.IsStudent) %>
这篇关于帮助 c# 和 bool 在 asp.net mvc 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文