Calling UpdateModel with a collection of complex data types reset all non-bound values?

前端 未结 3 2393
情话喂你
情话喂你 2020-12-01 13:17

I\'m not sure if this is a bug in the DefaultModelBinder class or what. But UpdateModel usually doesn\'t change any values of the model except the ones it found a match for.

3条回答
  •  遥遥无期
    2020-12-01 14:12

    Rudi Breedenraed just wrote an excellent post describing this problem and a very helpful solution. He overrides the DefaultModelBinder and then when it comes across a collection to update, it actually updates the item instead of creating it new like the default MVC behavior. With this, UpdateModel() and TryUpdateModel() behavior is consistent with both the root model and any collections.

提交回复
热议问题