Linked Questions

Popular Questions

The following syntax using ElementAt is working fine:

@Html.CheckBoxFor(m => m.Questions.ElementAt(QuestionIndex).QuestionDetails.ElementAt(j).IsSelected, new { name = "Questions[@QuestionIndex].QuestionDetails[@j].IsSelected" })

However when I change it to something like this using [], it does not work:

@Html.CheckBoxFor(m => m.Questions[QuestionIndex].QuestionDetails[j].IsSelected)

The model directive goes like this:

@model StandardVBA.ViewModels.AssessmentModel

AssessmentModel.cs

public class AssessmentModel
{
    public AssessmentModel()
    {
        this.Questions = new List<AssessmentQuestion>();
    }

    public int AssessmentID { get; set; }
    public string CourseName { get; set; }
    public string LessonName { get; set; }

    public int? CourseID { get; set; }
    public int? LessonID { get; set; }
    public int? UserID { get; set; }
    public int? Score { get; set; }
    public virtual ICollection<AssessmentQuestion> Questions { get; set;}
}

public class AssessmentQuestion
{
    public AssessmentQuestion()
    {
        this.QuestionDetails = new List<QuestionDetail>();
    }

    public int QuestionID { get; set; } //TODO
    public int QuestionNumber { get; set; } //TODO

    [MaxLength(1000)]
    public string Question { get; set; } // If this is NULL and ActionedByUserID is filled then action is DELETED
    public int Marks { get; set; }

    public virtual ICollection<QuestionDetail> QuestionDetails { get; set; }
}

public class QuestionDetail
{
    public int ChoiceNumber { get; set; }

    [MaxLength(500)]
    public string Choice { get; set; }
    public bool IsCorrect { get; set; }
    public bool IsSelected { get; set; }
}

The objective is to be able to use the model in the controller post method:

public void _Result(AssessmentModel Model)
{
    ...
}

Related Questions