日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

mvc @html.checkbox,MVC - @Html.CheckBoxFor

發(fā)布時間:2025/4/5 c/c++ 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mvc @html.checkbox,MVC - @Html.CheckBoxFor 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

問題

I need a checkbox but the underlying data is of type smallint in the database. Not sure how to make the @Html.Checkbox with that datatype. It complains saying the following:

Cannot implicitly convert type 'short?' to 'bool'

Here is the code that I have:

@Html.CheckBoxFor(model => model.HasCycle)

回答1:

If you are storing a boolean value in the database, then you should use the DB type 'bit' instead of smallint (where 0 will be false and 1 will be true).

Otherwise, you will need to first convert model.HasCycle to a bool. Also, since it is of type short? (nullable), you will need to handle null values too. You will probably want to handle this in the model itself, and publicly expose HasCycle from the model as a bool instead of a short. Still, you may run into some problems going back and forth, and the right way to do it is to change the database type.

To convert from a short? to a bool you can do something like:

bool hasCycleBool = false; //if HasCycle is null, this will remain false

if(model.HasCycle != null)

{

hasCycleBool = Convert.ToBoolean(model.HasCycle);

}

回答2:

I was having the same problem than you. We use smallint to map boolean values in our database, and we cannot change that.

I am developing a new ASP.NET MVC app, based on our existing database, so I have to deal with this issue.

The solution I adopted, was to create a not mapped boolean property to convert from and to my mapped (smallint / short) property. Like follows:

public short AllowMailing { get; set; }

[NotMapped]

public bool AllowMailingBool

{

get { return AllowMailing == 1? true : false; }

set { AllowMailing = value ? (short)1 : (short)0; }

}

It works fine.

回答3:

a checkbox is a boolean value, meaning true or false. if you are expecting true/false (1,0) you probably should set the database type to a bool. if you don't want to do this, you will have to convert the int value to a bool (1,0)

來源:https://stackoverflow.com/questions/8086029/mvc-html-checkboxfor

總結(jié)

以上是生活随笔為你收集整理的mvc @html.checkbox,MVC - @Html.CheckBoxFor的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产自产自拍 | 欧美精品一区二区三区视频 | www.色在线观看 | 无人在线观看高清视频 单曲 | 亚洲人成电影在线 | 噜噜吧噜噜色 | 免费成人黄色av | 少妇按摩一区二区三区 | 99色亚洲| 性色av免费观看 | 制服丝袜快播 | 亚洲国产网址 | 久久久精品久久久久久 | 国产亚洲一区二区三区不卡 | 99久久99久久精品国产片果冰 | 国产精品伦理 | 一个色av| www一起操 | 日日久| 亚洲第一页色 | 国产综合社区 | 永久免费不卡在线观看黄网站 | 看毛片网 | 欧美精品免费一区二区 | 99热8 | 色呦呦入口 | 日本成人在线网站 | 日本少妇高潮抽搐 | 国产男同gay网站 | 超碰2025| 亚洲最大中文字幕 | 91超碰免费| 欧美日韩色综合 | 操操操操操操操操操 | 国产又爽又黄免费软件 | 午夜剧场免费在线观看 | 美攻壮受大胸奶汁(高h) | 日本三级黄色录像 | 欧美888| 国产精品无码av在线播放 | 你懂的欧美 | 极品少妇xxxx精品少妇 | 欧美a级片在线观看 | www.日韩在线 | 视频在线观看你懂的 | 国产第9页| 777久久| 91污网站 | 伊人91在线 | 久久看看 | 亚洲高清视频一区 | 欧美日韩中文视频 | 成年人的免费视频 | jizz免费视频 | 69久久久 | 日本猛少妇色xxxxx | 国产一区二区三区免费在线观看 | 91丝袜一区在线观看 | 亚洲国产一区二区三区 | 国产亚洲激情 | 色网导航站 | 女人一区二区三区 | 国产精品四虎 | 久久色播 | 爆乳2把你榨干哦ova在线观看 | 女人下部全棵看视频 | 夜夜夜夜爽 | 亚洲欧美福利 | 日本中文在线 | 精品日韩在线 | 视频一区国产精品 | 看片免费黄在线观看入口 | 妺妺窝人体色777777 | 国产精品视频久久久久久 | 亚洲精品国产精品乱码不66 | 亚洲精品一区二区三区四区乱码 | 黄色av免费在线看 | 色狠狠一区二区三区香蕉 | brazzers欧美一区二区 | 97精品人妻一区二区三区在线 | 操操影视 | 国产精品2区| 孕妇毛片| 欧美精品在线免费 | 精品无码一区二区三区电影桃花 | 欧美性受xxxx黒人xyx性爽 | 男人扒女人添高潮视频 | 欧美91视频| 精品成人无码久久久久久 | 国产在线看一区 | 国内av自拍 | 国产日本精品视频 | 欧美精品第一页 | 校园春色欧美 | 国产精品视频福利 | 91tv在线观看 | 无码一区二区三区在线 | 一级性视频 | bt天堂新版中文在线地址 |