Is POSTing a Dictionary to an .NET MVC action possible?

前端 未结 3 556
轻奢々
轻奢々 2021-02-07 20:50

I have a form which contains a series of fields like:




        
3条回答
  •  爱一瞬间的悲伤
    2021-02-07 21:45

    For ASP.NET MVC 2 use this:

    
    
    
    
    
    

    You need an extra hidden field User[i].Key. i is zero-based index. It should be uninterrupted.

    when you model bind to a dictionary, you're actually binding to an ICollection>. So you need User[x].Key and User[x].Value (to reconstitute the KeyValuePair object)

    References

    • ASP.NET Wire Format for Model Binding to Arrays, Lists, Collections, Dictionaries by Scott Hanselman
    • ASP.NET MVC Model Binding Form Inputs To Action Parameters by Marco Magdy

提交回复
热议问题