I am trying to create a simple survey application and I am experiencing trouble accessing the survey's questions.
Survey Model
public class Survey
{
public Survey()
{
Questions = new List<Question>();
CompletedBy = new List<CompletedSurveys>();
}
public int SurveyID { get; set; }
public string Name { get; set; }
public List<Question> Questions { get; set; }
}
Question Model
public class Question
{
public int QuestionID { get; set; }
public int SurveyID { get; set; }
public string Title { get; set; }
}
And I auto generate input fields for the questions using the code below:
<input type="hidden" name="Questions['+ itemIndex +'].QuestionID"></input>
Which renders to:
<input type="hidden" name="Questions[0].QuestionID">
What am I doing wrong? It seems like I am inserting the questions into the list incorrectly. Since my model's questions are always null.
Any guidance would be greatly appreciated.