views:

213

answers:

2

I have the following code:

var obj = new
            {
                site = new int[]{}
            };

UpdateModel(obj, new string[] {"site"}, form.ToValueProvider());

Now when debugging, the form.ToValueProvider() object has a site key in there with some sites that get populated on postback (from a checkbox form with each checkbox name set to "site"). However the site int array property does not get populated and bound when I call the UpdateModel call. Is this a valid and possible use of UpdateModel? Am I missing something or is there another way around it?

+1  A: 

Anonymous objects' propeties are readonly, and arrays are immutable in length. These two things combine to make this particular usage of UpdateModel() invalid.

You can probably accomplish what you want by writing your action method to have an int[] site parameter. The binder should recognize that pattern and create an array to pass into your method.

Levi
A: 

Thank you so much, I can't tick Levi's answer as the correct answer for some reason. Thanks for the help that solved it.