This is a migrated thread and some comments may be shown as answers.

ModelBinding, DropDownList and complex objects

0 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
JULIA
Top achievements
Rank 1
JULIA asked on 24 Sep 2010, 09:42 AM
Hello,

i have the following class structure:
public class PhysicianGridViewModel : PersonViewModel
    {
        public PhysicianGridViewModel() {}
        public PhysicianGridViewModel( Physician physician ) : base( physician )
        {
            this.Contingent = new ContingentViewModel( new Contingent { ContingentType = new ContingentType { ContingentTypeId = 1 } } );
        }
        public int ProjectId { get; set; }
        public ContingentViewModel Contingent { get; set; }
    }
  
    [Bind( Exclude = "ContingentType" )]
    public class ContingentViewModel
    {
        public ContingentViewModel() {}
        public ContingentViewModel( Contingent contingent )
        {
            this.ContingentId = contingent.ContingentId;
            this.ContingentType = new ContingentTypeViewModel( contingent.ContingentType );
        }
        [ScaffoldColumn( false )]
        public int ContingentId { get; set; }
        [UIHint( "ContingentType" )]
        public ContingentTypeViewModel ContingentType { get; set; }
        // ...
    }
  
    public class ContingentTypeViewModel
    {
        public ContingentTypeViewModel() { }
        public ContingentTypeViewModel( ContingentType contingentType )
        {
            this.ContingentTypeId = contingentType.ContingentTypeId;
            this.TypeName = contingentType.TypeName;
        }
          
        public int ContingentTypeId { get; set; }
        public string TypeName { get; set; }
    }

ContingentType is shown in a DropDownList. How can i bind this value inside the update method?
The Key in the FormCollection is Contingent.ContingentType. But the ModelBinder won't bind this value.
[GridAction( EnableCustomBinding = true )]
[HttpPost]
public ActionResult _Update( GridCommand command, PhysicianGridViewModel model, int? contingent_ContingentType /* the value from dropdownlist */ )
{
    var t = Request.Form["Contingent.ContingentType"]; // this is the value
    return View();
}

Regards,
Timo
Tags
Grid
Asked by
JULIA
Top achievements
Rank 1
Share this question
or