0

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 .

3

2 Answers 2

1

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.

0

cast your nullable value to value type

public ActionResult Index(bool? checkOffAge)
{
    if (checkOffAge != null) {
       model.CheckOffAge =(bool)checkOffAge;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.