わかりましたこれを理解しました。選択したセキュリティの質問と回答だけを保持するために文字列型を使用しました。
public class RegisterFormViewModel
{
...
[Required]
[Display(Name = "Security Question")]
public string SecurityQuestion { get; set; }
[Required]
[Display(Name = "Security Answer")]
public string SecurityAnswer { get; set; }
...
}
次に、次のようにリストを作成しました。
@Html.DropDownListFor(m => m.SecurityQuestion, QuestionHelper.GetSecurityQuestions())
このヘルパーの使用:
public static IEnumerable<SelectListItem> GetSecurityQuestions()
{
return new[]
{
new SelectListItem { Value = "What was your childhood nickname?", Text = "What was your childhood nickname?"},
new SelectListItem { Value = "What is the name of your favorite childhood friend?", Text = "What is the name of your favorite childhood friend?"},
new SelectListItem { Value = "What school did you attend for sixth grade?", Text = "What school did you attend for sixth grade?"},
new SelectListItem { Value = "In what city or town did your mother and father meet?", Text = "In what city or town did your mother and father meet?"},
new SelectListItem { Value = "What is the first name of the boy or girl that you first kissed?", Text = "What is the first name of the boy or girl that you first kissed?"},
new SelectListItem { Value = "What is the name of a college you applied to but didn't attend?", Text = "What is the name of a college you applied to but didn't attend?"},
new SelectListItem { Value = "Where were you when you first heard about 9/11?", Text = "Where were you when you first heard about 9/11?"},
new SelectListItem { Value = "What is your grandmother's first name?", Text = "What is your grandmother's first name?"},
new SelectListItem { Value = "What was the make and model of your first car?", Text = "What was the make and model of your first car?"},
new SelectListItem { Value = "In what city and country do you want to retire?", Text = "In what city and country do you want to retire?"}
};
}
次に、次のような ajax 投稿を行いました。
$.post('/Account/Register', $('#registerForm').serialize(), function(){ //success });
jQuery シリアル化メソッドは、セキュリティの質問に対して選択された項目の「値」を送信します。Value と Text を同じものに設定する理由である実際の質問が必要でした。それ以外の場合は、項目が選択された場合に取得したい値を設定できます。