处理TINYINT布尔值与MVC [英] Handling tinyInt booleans with MVC

查看:225
本文介绍了处理TINYINT布尔值与MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆