私は単純なクイズモデルを持っており、強く型付けされたビューでグループ化された2つのラジオボタンからユーザーが正解/代替回答を選択できるようにしようとしています。しかし、私が使用するラムダ式は機能しません。空のラジオ ボタンが 2 つ表示されます。こことオンラインでいくつかの質問を見てきましたが、私のモデルは IList<> であり、適切な例が見つかりません。私が見つけたすべての例は、非 IList<> で動作します。
これは私のモデルです
モデル:
public partial class Question
{
public int QuestionID { get; set; }
public string QuestionBody { get; set; }
public string CorrectAnswer { get; set; }
public string AlternativeAnswer { get; set; }
}
私のコントローラー
public ActionResult Index()
{
QuizSimpleEntities quizEntities = new QuizSimpleEntities();
var questions = from p in quizEntities.Questions
select p;
return View(questions.ToList());
}
私のモデル:
@model IList<Quiz.Models.Question>
<h2>Welcome to the Quiz</h2>
@Html.BeginForm(method:FormMethod.Post,controllerName:"Home",actionName:"index")
{
@foreach (var questions in Model)
{
<p>@questions.QuestionBody</p>
@* How to display the CorrectAnswer and AlternativeAnswer
as two radio buttons grouped here? I will be posting the selected value back
}
}
ありがとうございました