Question: I am trying to get the `id` of an `input field` which has a dynamic id but I get an error unrecognized expression. Below is my code : 

```
  $("#amount_paid' + data[i].patient_visit_statement_id + '").keyup(function() {
       var amount_owed = $('#amount_owed' + data[i].patient_visit_statement_id + '').val();
       var amount_paid = $('#amount_paid' + data[i].patient_visit_statement_id + '').val();
       alert('Amount owed' + amount_owed + 'Amount paid' + amount_paid + '');
       if (amount_owed < amount_paid) {
           alert('Amount to be paid exceeds amount owed');
       }
   });

```

What is the best way to get the value from the id amount\_paid which has dynamic id for each entry ?

Answer: 
According to your question

> 
> Basically, I am interest*ed* in finding out if a simple bool variable is true OR if a Nullable variable is not null.
> 
> 
> 

* to tell if a simple boolVariable is true

```
 if(boolVariable){
      //bool variable, not nullable
 }

```
* to tell if your nullableVariable is not null

```
 if(nullableVariable.HasValue){
     //a nullable variable is not null
 }

```
* to tell if nullable bool variable is true or/and not null, use the `??` operator

```
if(variable??false){
   //then I'm sure that this is not null and has value=true
}

```

So in definitive you can use the following code for both nullable bool and bool variables

```
     if(variables!=null &&variables!=false){/*This may give a warning message but it works*/}

```

or

```
   if(((bool?)variable)??false){
      /*variable is not null and is true*/
    }

```
Try this

```
List<string> values = typeof(InstViewModel).GetProperties()
    .Select(prop => new { N = prop.Name, T = prop.PropertyType, V = prop.GetValue(ivm, null) })
    .Where(prop => prop.N != "SubCollection" && prop.N != "ID" && prop.N != "Name" && prop.N != "Level")
    .Where(val => (val.V != null && val.T.IsAssignableFrom(typeof(Nullable<bool>))) || Convert.ToBoolean(val.V))                    
    .Select(val => val.V.ToString())
    .Where(str => str.Length > 0)
    .ToList();

```