问题描述
我有一个列MySQL表的设置与TINYINT的数据类型(1)。这将重新presents一个布尔值。
0 = FALSE; 1 =真。
我还设置了一个网站,以显示此信息使用asp.net和MVC设计公司。现在,该表显示了列
是在网上记录| [下一列]
------------------------------------
1 |破烂
1 |破烂
0 |破烂
不过,我想在1和0,显示为真/假或是/否。基本上只是一些更加人性化。
我应该怎么做随着对自身的ViewPage或在控制器中的foreach循环,如脚本:
的foreach(ListViewModel我DefaultList)
{
如果(i.RecordsOnline ==真)
{//设置为yes
}
否则,如果(i.RecordsOnline = FALSE)
{//设置为无
}
}
只需使用一个简单的三元打印文本的相应位在您的视图:
@(i.RecordsOnline是:否)
I have a mySQL table setup with a column with a datatype of TinyInt(1). This represents a boolean.
0 = false; 1 = true.
I'm also setting up a website to show this information to the company using asp.net and the MVC design. Right now, the table shows the column as:
"Are Records Online"| [next column]
------------------------------------
1 | junk
1 | junk
0 | junk
However, i want the 1's and 0's to display as 'true/false' or 'yes/no'. Basically just something more user-friendly.
How should i do this? With a script on the Viewpage itself or with a foreach loop in the controller such as:
foreach(ListViewModel i in DefaultList)
{
if(i.RecordsOnline == true)
{ //set to 'yes'
}
else if(i.RecordsOnline = false)
{ //set to 'no'
}
}
Just use a simple ternary to print the appropriate bit of text in your view:
@(i.RecordsOnline ? "Yes" : "No")
这篇关于处理TINYINT布尔值与MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!