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: 
You can distinguish the boolean and nullable boolean properties before you evaluate them. Then there is no need to worry about whether they evaluate to a `bool` or a `Nullable<bool>`:

```
var nullableBooleanProperties = typeof(InstViewModel).Where(prop => prop.PropertyType == typeof(bool?));

```

Then you can simply write these out to a list of strings:

```
var values = nullableBooleanProperties.Select(prop => prop.GetValue(ivm)).Where(val => val != null).Select(val => val.ToString());

```

Putting these together gives:

```
var values = typeof(InstViewModel).Where(prop => prop.PropertyType == typeof(bool?))
    .Select(prop => prop.GetValue(ivm)).Where(val => val != null)
    .Select(val => val.ToString())
    .ToList();

```

which gives you the list you are looking for.
Try this:

```
((bool?)val).HasValue

```

This will return `true`, if `val` is a `bool` **or** if `val` is a `bool?` which value is not `null`.

On the other hand,

```
!((bool?)val).HasValue

```

will only return `true` if val is `bool?` **and** its value is `null`.

Will not that test suffice in your case?