Custom Model Binder for Complex composite objects HELP

前端 未结 2 468
太阳男子
太阳男子 2020-12-17 00:12

I am trying to write a custom model binder but I\'m having great difficulty trying to figure how to bind complex composite objects.

this is the class I\'m trying to

2条回答
  •  没有蜡笔的小新
    2020-12-17 00:52

    Do you really need to implement a custom ModelBinder here? The default binder may do what you need (as it can populate collections and complex objects):

    Lets say your controller action looks like this:

    public ActionResult SomeAction(Fund fund)
    {
      //do some stuff
      return View();
    }
    

    And you html contains this:

    
    
    
    
    
    
    
    
    

    The default model binder should initialise your fund object with 2 items in the FundAllocations List (I don't know what your FundAllocation class looks like, so I made up a single property "SomeProperty"). Just be sure to include those "fund.FundAllocations.Index" elements (which the default binder looks at for it's own use), that got me when I tried to get this working).

提交回复
热议问题