C # ASP.NET MVC: ошибка при использовании HtmlHelper с использованием синтаксиса массива - PullRequest
0 голосов
/ 03 февраля 2019

Следующий синтаксис с использованием ElementAt: работает нормально:

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

Однако, когда я изменяю его на что-то подобное, используя [], он не работает:

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

Директива модели выглядит следующим образом:

@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; }
}

Цель состоит в том, чтобы иметь возможность использовать модель в методе поста контроллера:

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