mvc3 ignore null values when binding a list?

222 Views Asked by At

I have a custom model binder that either returns the complete object or a null. This custom model binder is operating on a list so in my controller I get a list of either a complete object or a null.

Is there any way to get rid of the nulls in the list before the binded object reaches the controller?

Can I create a custom model binder for lists of specific type which filter out the nulls?

1

There are 1 best solutions below

0
On

You could use a linq expression with the original list to make sure the elements don't contain nulls.

Before executing this command, check that list is not null.

var listWoNulls = from l in list where l != null select l