Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert bool? to bool in View

i have checkbox in my which is like this @Html.CheckBoxFor(model => model.SKUs.Jewish) but my Jewish in database is nullable type so it gives me an error cannot implicitly convert type 'bool?' to 'bool'. how do check my model that it has values then it should show that else not.please help.

like image 573
DharaPPatel Avatar asked Jun 11 '13 09:06

DharaPPatel


1 Answers

You could use the following:

@Html.CheckBox("SKUs.Jewish", Model.SKUs.Jewish.GetValueOrDefault());

If the value is not set it uses the nullable types default value which is false.

like image 64
hutchonoid Avatar answered Oct 17 '22 02:10

hutchonoid