I've created a DTO with following members:
public List<Guid> QuestionIds { get; set; }
public List<Guid> AnswerIds { get; set; }
public CompetitionDTO Competition { get; set; }
I wanna display a list of questions contained several answers to show for users and let them to choose the correct answers of any question that he/she is sure about. CompetitionDTO has the following style:
public class CompetitionDTO
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public IList<QuestionDTO> Questions { get; set; }
}
and the QuestionDTO:
public class QuestionDTO
{
public Guid Id { get; set; }
public string Title { get; set; }
public string Category { get; set; }
public IList<AnswerDTO> Answers { get; set; }
}
public class AnswerDTO
{
public Guid Id { get; set; }
public int Order { get; set; }
public string Title { get; set; }
}
now in razor view I written this:
@for (var i = 0; i < Model.Competition.Questions.Count; i++)
{
@Html.DisplayTextFor(x => x.Competition.Questions[i].Title)
foreach (var t in Model.Competition.Questions[i].Answers)
{
@Html.DisplayFor(c => t.Title)
@Html.RadioButtonFor(x => x.Competition.Questions[i].Answers, false, new { Model = t.Id })
}
}
but it doesn't work when I pass the data to post action, I want to get the all selected answers with theirs questions, How should I solve this? thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…