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

前端 未结 3 2421
情话喂你
情话喂你 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 13:51

    You just gave me an idea to dig into ASP.NET MVC 2 source code. I have been struggling with this for two weeks now. I found out that your solution will not work with nested lists. I put a breakpoint in the UpdateCollection method ,and it never gets hit. It seems like the root level of model needs to be a list for this method to be called

    This is in short the model I have..I also have one more level of generic lists, but this is just a quick sample..

    public class Borrowers
    {
       public string FirstName{get;set;}
       public string LastName{get;set;}
       public List
    Addresses{get;set;} }

    I guess that, I will need to dig deeper to find out what is going on.

    UPDATE: The UpdateCollection still gets called in asp.net mvc 2, but the problem with the fix above is related to this HERE

提交回复
热议问题