日韩性视频-久久久蜜桃-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)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 免费av高清| 色黄视频在线观看 | 熟妇人妻无乱码中文字幕真矢织江 | 国产精品综合久久久久久 | 亚洲日本欧美在线 | 佐山爱在线视频 | 中文字幕在线观看一区 | 国产午夜精品无码 | 青青草国产一区二区三区 | 69xx欧美| 高清欧美精品xxxxx在线看 | h片在线免费 | 右手影院亚洲欧美 | 欧美大片高清 | 婷婷射图| 亚洲av无码精品色午夜果冻不卡 | 国产精品国产馆在线真实露脸 | 久久久久久av | 看日本黄色录像 | 中文自拍 | 小镇姑娘1979版 | 美女娇喘 | av大帝在线观看 | 亚洲最大的黄色网 | 久久亚洲日本 | www.一区二区 | 中文字幕乱码一区二区三区 | 国产aaa| 国产视频一区二区三区在线 | 成人在线观看免费 | 亚洲精品网站在线播放gif | 亚洲欧美日本一区二区三区 | 波多野结衣亚洲 | 国产精品黄色在线观看 | 黄色av网址大全 | 亚洲国产欧美日韩在线 | 国产黄片毛片 | 日本免费色| 懂色av成人一区二区三区 | 国内精品少妇 | 99re这里只有精品在线 | 久久综合九九 | 草莓视频在线观看入口w | 亚洲怡红院av| 一级全黄男女免费大片 | 女性女同性aⅴ免费观女性恋 | 亚洲成a人 | 加勒比精品在线 | 一区国产精品 | 亚洲视频 一区 | 色先锋在线 | av在线大全 | jizzjizz美国| 亚洲乱仑 | 女人脱了内裤趴开腿让男躁 | 懂色一区二区 | 姐姐你真棒插曲快来救救我电影 | 国产精品久久777777换脸 | 色哟哟在线播放 | 午夜粉色视频 | 欧美国产日韩一区二区 | 日本成人一区二区 | 6080福利| 亚洲日本网站 | 欧美在线网站 | 粉嫩欧美一区二区三区 | 黄瓜视频91 | 善良的女朋友在线观看 | 男女扒开双腿猛进入爽爽免费 | 在线观看国产精品入口男同 | 一区二区三区视频网 | 香蕉视频99 | 九九这里只有精品视频 | 日韩中文第一页 | 欧美三级电影在线观看 | www.youjizz.com亚洲| 久久高清无码视频 | 亚洲精品视频91 | 久久久久亚洲精品系列色欲 | 靠逼网站在线观看 | 欧美日韩激情在线观看 | 在线观看免费视频一区 | 亚洲精品二区三区 | 老色批影视 | 精品无码一区二区三区蜜臀 | 俺去俺来也在线www色官网 | 狠狠热免费视频 | 国产电影一区在线观看 | 亚洲一区二区三区四区 | 好男人在线观看 | 成人三级电影网站 | 91精品人妻一区二区三区四区 | 国产黄片一区二区三区 | 欧美色图亚洲视频 | 久久久久久久久久久久久久久 | 99riav在线 | 桃花久久| 日韩欧美在线观看一区二区 | 国产福利视频一区二区 |