Reputation: 85
I had delared :
public bool Valuetype { get; set; }
in my model and in controller used Valuetype = s.IsValueType
which is resulting Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) error .
Upvotes: 0
Views: 3323
Reputation: 825
cast your nullable value to value type
public ActionResult Index(bool? checkOffAge)
{
if (checkOffAge != null) {
model.CheckOffAge =(bool)checkOffAge;
}
}
Upvotes: 0
Reputation: 84540
Apparently s
is a Nullable<bool>
, also written as bool?
. This is a value that can be a bool
or it can be null
. It's not valid to simply assume that it's a bool
; you need to test to make sure it's not null
first, and handle the null
appropriately if it is.
If it doesn't make sense in this context for it to be a null
at all, then try to fix the type of s
to be a regular bool
.
Upvotes: 1