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:
<input type="text" name="fund.Id" value="1" />
<input type="text" name="fund.Name" value="SomeName" />
<input type="text" name="fund.FundAllocations.Index" value="0" />
<input type="text" name="fund.FundAllocations[0].SomeProperty" value="abc" />
<input type="text" name="fund.FundAllocations.Index" value="1" />
<input type="text" name="fund.FundAllocations[1].SomeProperty" value="xyz" />
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).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…