사용자 지정 모델 바인더를 쓰려고하는데 복잡한 복합 개체를 바인딩하는 방법을 찾는 데 어려움을 겪고 있습니다. 복잡한 복합 개체 용 사용자 지정 모델 바인더 HELP
이
내가 바인딩려고하는 클래스입니다 :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;
}
}
어떤 아이디어
감사합니다 토니
방금 질문을 올린 다음 결국 동일한 유형의 문제에 대한 해결책을 찾았습니다. 관심있는 사람들을 위해 아래 링크를 확인해보십시오. [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) –