I'm new to MVC/Web developmnent and I'm facing a big trouble with no answer here: RadioButtonFor for a list of objects mvc
So, I'm trying to understand.
Considering I have these Model :
public class ChartsViewModel
{
public HistoricViewModel HistoricViewModel { get;set;}
}
public class HistoricViewModel
{
public PeriodViewModel SelectedPeriod { get; set; }
public IEnumerable<PeriodViewModel> AllPeriodes { get; set; }
}
public class PeriodViewModel
{
public int Id { get; set; }
public bool Selected { get; set; }
public string DisplayText { get; set; }
public string PickerFormat { get; set; }
}
ChartsViewModel
is the model used in the view.
Now I'm trying to understand the binding and I wrote this hard coded HTML to do that.
<input id="HistoricViewModel_SelectedPeriod_Selected" name="HistoricViewModel.SelectedPeriod.Selected" type="hidden" value="True" />
<input id="HistoricViewModel_SelectedPeriod_PickerFormat" name="HistoricViewModel.SelectedPeriod.PickerFormat" type="hidden" value="formatA" />
<input id="HistoricViewModel_SelectedPeriod_Id" name="HistoricViewModel.SelectedPeriod.Id" type="radio" value="1" />
<input id="HistoricViewModel_SelectedPeriod_DisplayText" name="HistoricViewModel.SelectedPeriod.DisplayText" type="hidden" value="pariodeA" />
<input id="HistoricViewModel_SelectedPeriod_Selected1" name="HistoricViewModel.SelectedPeriod.Selected" type="hidden" value="False" />
<input id="HistoricViewModel_SelectedPeriod_PickerFormat1" name="HistoricViewModel.SelectedPeriod.PickerFormat" type="hidden" value="formatB" />
<input id="HistoricViewModel_SelectedPeriod_Id1" name="HistoricViewModel.SelectedPeriod.Id" type="radio" value="2" />
<input id="HistoricViewModel_SelectedPeriod_DisplayText1" name="HistoricViewModel.SelectedPeriod.DisplayText" type="hidden" value="pariodeB" />
In this case only the property Id
associated with the radio button is binded.
How to bind the others?
Many thanks for your help.