だから、RadioButtonFor の選択された値を返す方法を理解しようとしています。シンプルなはずですが、何かが欠けています。
私が持っているビューで:
@for (int i = 0; i < Model.ProfessionalRelations.Count; i++)
{
@Html.RadioButtonFor(m => m.SelectedProfessionalRelations, Model.ProfessionalRelations, new { id = "professionalRelations_" + i})
@Html.HiddenFor(m => m.ProfessionalRelations[i].Text)
@Html.Raw("<span style=\"padding-left: 5px; \">");
@Html.DisplayFor(m => m.ProfessionalRelations[i].Text)
@Html.Raw("</span><br />")
}
コントローラーには、次のものがあります。
rvm.ProfessionalRelations = new List<RadioButton>();
rvm.ProfessionalRelations.AddRange(AccountHelper.professionalRelations(rvm.SelectedProfessionalRelations));
AccountHelper には、次のようなものがあります。
public static List<RadioButton> professionalRelations(string selectedText)
{
var pr = new List<RadioButton>()
{
new RadioButton {Text = "None", ToolTip = "None", Checked = selectedText == "None"},
new RadioButton {Text = "Orthotic/Prosthetic Practitioner", ToolTip = "Orthotic/Prosthetic Practitioner", Checked = selectedText == "Orthotic/Prosthetic Practitioner"},
new RadioButton {Text = "Orthotic/Prosthetic Resident", ToolTip = "Orthotic/Prosthetic Resident", Checked = selectedText == "Orthotic/Prosthetic Resident"},
new RadioButton {Text = "Orthotic/Prosthetic Student", ToolTip = "Orthotic/Prosthetic Student", Checked = selectedText == "Orthotic/Prosthetic Student"},
new RadioButton {Text = "O&P Technician (including Students)", ToolTip = "O&P Technician (including Students)", Checked = selectedText == "O&P Technician (including Students)"},
new RadioButton {Text = "Non-Clinical Employee of an O&P practice", ToolTip = "Non-Clinical Employee of an O&P practice", Checked = selectedText == "Non-Clinical Employee of an O&P practice"},
new RadioButton {Text = "Employee of an O&P Manfacturer/Distributor or other related company", ToolTip = "Employee of an O&P Manfacturer/Distributor or other related company", Checked = selectedText == "Employee of an O&P Manfacturer/Distributor or other related company"},
new RadioButton {Text = "HealthCare Professional (non O&P)", ToolTip = "HealthCare Professional (non O&P)", Checked = selectedText == "HealthCare Professional (non O&P)"},
new RadioButton {Text = "Other", ToolTip = "Other", Checked = selectedText == "Other"}
};
return pr;
}
私が投稿するとき:
rvm.ProfessionalRelations = new List<RadioButton>();
rvm.ProfessionalRelations.AddRange(AccountHelper.professionalRelations(rvm.SelectedProfessionalRelations));
しかし、何らかの理由で rvm.SelectedProfessionalRelations が「System.Collections.Generic.List`1[System.Web.UI.WebControls.RadioButton]」として返されます。
あなたがページに行くとき、私は次のことを追加する必要があります:
rvm.ProfessionalRelations = new List<RadioButton>();
rvm.ProfessionalRelations.AddRange(AccountHelper.professionalRelations("None"));
しかし、何も選択されていません。
RadioButtonFor を次のように変更しようとしました
@Html.RadioButtonFor(m => m.SelectedProfessionalRelations, Model.ProfessionalRelations, new { id = "professionalRelations_" + i, @checked = Model.ProfessionalRelations[i].Checked})
ただし、それでも何も選択されません (ページまたは投稿に移動したとき)。
デバッグ モードで実行中に AccountHelper を確認したところ、「なし」がチェックされていることが示されていますが、それは反映されていません。
どんな助けでも大歓迎です!