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

主站蜘蛛池模板: 国产成人免费观看视频 | 亚洲精品视频在线观看视频 | 一本大道东京热无码aⅴ | 国产一区午夜 | 欧美日韩xxxx| 少妇一级淫片aaaaaaa | 久久久国产成人一区二区三区 | 欧美午夜激情影院 | 日日夜夜免费精品视频 | 精品国产1区2区 | 久久久久久av无码免费网站 | 看全黄大色黄大片 | 久操久操| 性人久久久久 | 日本少妇裸体做爰高潮片 | 狠狠看| 亚洲成人精品视频 | 美女张开双腿让男人捅 | 无码国产色欲xxxx视频 | 影音先锋在线中文字幕 | china国模大尺度pics | 蜜桃av影视 | 色妻av| 人人妻人人澡人人爽精品 | 天天看夜夜 | 30一40一50老女人毛片 | 日本xxxx裸体xxxx | 亚洲欧美激情视频 | 日本一区欧美 | 欧美一区二 | 中文字幕欧美色图 | 久久综合网址 | 日韩欧美色图 | 九九成人| 日韩成年视频 | 欧美日韩一区二区三区在线观看 | 嫩草影院av| 亚洲不卡影院 | 波多野结衣国产在线 | 超碰997| 天天综合久久综合 | 精品在线视频观看 | 小镇姑娘高清播放视频 | 波多野结衣视频免费 | 国内精品嫩模av私拍在线观看 | 日韩av免费一区 | 伊人免费在线观看高清版 | www99re| www.国产91 | 国产刺激高潮av | 美女色综合 | 高清国产午夜精品久久久久久 | 日韩高清av | 国产精品免费久久久 | 欧美性xxxx在线播放 | 青青青青操 | 日本人の夫妇交换 | 伊人色综合网 | 三级小视频在线观看 | 乱淫的女高中暑假调教h | fc2成人免费视频 | 日韩第一页在线观看 | 高清国产mv在线观看 | 国产不卡a| 在线观视频免费观看 | 视频一区二区欧美 | 在线中文字幕av | 天天天天天天操 | 日韩激情网站 | 欧美国产一级 | 91看片免费看| 精品日本一区二区 | 黄色一级视频网站 | 91精品国产综合久久久蜜臀九色 | 亚洲一线av | 男人的天堂av女优 | 欧美一级淫片免费视频黄 | 欧美亚洲在线 | 亚洲黄色在线观看视频 | 亚色视频在线 | 成人av高清| 一级欧美在线 | 婷婷影视 | 亚洲最黄网站 | 国产av电影一区二区 | 99有精品| 精品无码av一区二区三区 | 欧美成人aaa片一区国产精品 | 91精品国产91综合久久蜜臀 | 国产精品毛片久久久久久久 | 久久亚洲精品小早川怜子 | 欧美另类z0zx974| 亚洲色诱| 国产小视频免费观看 | 亚洲一片 | 超碰在线97国产 | 最近最经典中文mv字幕 | 福利影院在线观看 | 国产毛片一区二区三区va在线 |