I have a simple quiz model, and I am trying to let the user select Correct Answer/Alternative answer from two radio buttons, grouped , in a strongly typed view. But the lambda expressions I use aren't working. I get two blank radio buttons. I have looked at several questions here, and online but my model is an IList<>, and I can't find a suitable example. All examples I found work with a non-IList<>.
This is my Model
Model:
public partial class Question
{
public int QuestionID { get; set; }
public string QuestionBody { get; set; }
public string CorrectAnswer { get; set; }
public string AlternativeAnswer { get; set; }
}
My Controller
public ActionResult Index()
{
QuizSimpleEntities quizEntities = new QuizSimpleEntities();
var questions = from p in quizEntities.Questions
select p;
return View(questions.ToList());
}
My Model:
@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
}
}
Thank you