カスタムモデルバインダーを作成しようとしていますが、複雑な複合オブジェクトをバインドする方法を理解しようとすると非常に困難です。複雑な複合オブジェクトのカスタムモデルバインダーヘルプ
これは私がにバインドしようとしているクラスである:任意のアイデア
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;
}
}
:
public class Fund
{
public int Id { get; set; }
public string Name { get; set; }
public List<FundAllocation> FundAllocations { get; set; }
}
と、これはカスタムバインダーを書く時、私の試みがどのように見えるかですありがとう トニー
私はちょうど質問を投稿し、ついにこの同じ種類の問題に対する解決策を見つけました。興味のある方は、以下のリンクをご覧ください:[http://stackoverflow.com/questions/1077481/how-do-i-pass-a-dictionary-as-a-parameter-to-an-actionresult -method-from-jquery-a](http://stackoverflow.com/questions/1077481/how-do-i-pass-a-dictionary-as-a-parameter-to-an-actionresult-method-from- jquery-a) –