tags:

views:

1832

answers:

1

I've some simple questions regarding asp.net mvc development.

What the use of UpdateModel and TryUpdateModel ? and which condition does apply to use either UpdateModel or TryUpdateModel. From my experience TryUpdateModel beside binding FormCollection into Model also validate the data. Is it correct ?

+3  A: 

You're right, both methods are used to update the Model with the Form values and perform the validations. There's a default binder but you can build custom ones if needed.

The difference between the two methods is that UpdateModel will throw an exception if validation fails and TryUpdateModel will inform about the validation result in a boolean.

antonioh
Does TryUpdateModel and UpdateModel always use of DefaultModelBinder instead of CustomModelBinder ?
Funky81
I believe that if you use CustomModelBinders, there's no real need of caling explicitly the UpdateModel methods because they are executed in the background when the form is binded to the parameter of your Action method.
antonioh