views:

126

answers:

3

I have an edit page to edit some info. the page fills a complex object. one of the properties of this object is a generic list.

If I just edit information and save, updatemodel works fine. if i remove (I do this using jquery to remove the form elements client side) something from the list the updatemodel fails with an "object not set to an instance".

I guess the update model is expecting the list to remain of the same legth or something but cannot find any information about this, any ideas?

A: 

The model binder will try to map your complex object properties retrieving data from:
1) values from the RouteData
2) URI query string
3) request form submission
Check this places to see why your property is null. If you're deleting your form elements your property will not receive any data. Some info here and a bug analysis by Scott Hanselman here.

Eduardo Campañó
A: 

Thanks for the answer, I think that the problem is I am removing a form element. it seems to me that the default modelbinder is expecting to create ,say, 2 objects in the list but is only receiving 1. I am wondering what I can do to allow this ability to work

Pharabus
+1  A: 

OK, figured out the problem (and it was of course programmer error) on the jquery remove routine I had removed all the elements EXCEPT the hidden field that the model binder uses for lists :(

Pharabus