したがって、RadioButtonForの選択値を返す方法を理解しようとしています。シンプルでなければならないが、私は何かを欠いている。ビューで RadioButton選択値を返さない
私が持っている: コントローラで@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 />")
}
、私は以下があります。AccountHelperで
rvm.ProfessionalRelations = new List<RadioButton>();
rvm.ProfessionalRelations.AddRange(AccountHelper.professionalRelations(rvm.SelectedProfessionalRelations));
、ここで私が持っているものです。
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"));
何も選択されていません。
私は
@Html.RadioButtonFor(m => m.SelectedProfessionalRelations, Model.ProfessionalRelations, new { id = "professionalRelations_" + i, @checked = Model.ProfessionalRelations[i].Checked})
するRadioButtonForを変更しようとしたが、それはまだ何も選択しない(どちらかのページまたはポストに行くとき)。
デバッグモードで実行中、私はAccountHelperをチェックし、 "なし"がチェックされているがそれはそれを反映していないことを示しています。
ご協力いただければ幸いです!
次の '@ Html.RadioButtonFor'の簡単なGoogle検索を実行しましたか? – MethodMan
' RadionButtonFor'の2番目のパラメータは、この特定のボタンの値にする必要があります。おそらく、それは 'Model.ProfessionalRelations [i] .Text'なのか、それと似たものなのでしょうか。あなたが隠れたフィールドで何をやっているのかわからない...ちょっと変わったようです。 –
これをModel.ProfessionalRelations [i] .Textに変更しましたが、まだ運がありません。 – ajtatum