カスタム モデル バインダーを作成しようとしていますが、複雑な複合オブジェクトをバインドする方法を理解するのが非常に困難です。
これは私がバインドしようとしているクラスです:
public class Fund
{
public int Id { get; set; }
public string Name { get; set; }
public List<FundAllocation> FundAllocations { get; set; }
}
これは、カスタムバインダーを作成しようとする私の試みがどのように見えるかです:
public class FundModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
throw new NotImplementedException();
}
public object GetValue(ControllerContext controllerContext, string modelName, Type modelType, ModelStateDictionary modelState)
{
var fund = new Fund();
fund.Id = int.Parse(controllerContext.HttpContext.Request.Form["Id"]);
fund.Name = controllerContext.HttpContext.Request.Form["Name"];
//i don't know how to bind to the list property :(
fund.FundItems[0].Catalogue.Id = controllerContext.HttpContext.Request.Form["FundItem.Catalogue.Id"];
return fund;
}
}
何か案は
ありがとうトニー