1

我有一个包含问题的表格,我还有一个表格,其中包含在答案表中列出的问题 ID。为了重复数据,我只使用 id。

我的问题是如何根据当前表中的 ID “在视图中”填充问题。MainQuestionID 已经加入了它们。我首先使用 DBEntities 代码。

这是我的页面视图模型。

    public class AuditFormEdit
    {
    public Models.MainQuestion MainQuestionID { get; set; }

    public ICollection<MainQuestion> mainQuestion { get; set; }

    public List<SubcategoryHelper> SubcategoryHelperGet { get; set; }

    public class SubcategoryHelper : Models.SubCategory
    {
        public SubcategoryHelper(Models.SubCategory subCat)
        {
            this.SubCategoryID = subCat.SubCategoryID;
            this.SubcategoryName = subCat.SubcategoryName;
        }

    }


    public Models.MainAnswer MainAnswerInstance { get; set; }

    public List<ScoreCardCheckBoxHelper> ScoreCardCheckBoxHelperList { get; set; }

    public void InitializeScoreCheckBoxHelperList(List<Models.Score> ScoreList)
    {
        if (this.ScoreCardCheckBoxHelperList == null)
            this.ScoreCardCheckBoxHelperList = new List<ScoreCardCheckBoxHelper>();

        if (ScoreList != null
            && this.MainAnswerInstance != null)
        {
            this.ScoreCardCheckBoxHelperList.Clear();
            ScoreCardCheckBoxHelper scoreCardCheckBoxHelper;
            string scoreTypes =
                string.IsNullOrEmpty(this.MainAnswerInstance.Score) ?
                string.Empty : this.MainAnswerInstance.Score;
            foreach (Models.Score scoreType in ScoreList)
            {
                scoreCardCheckBoxHelper = new ScoreCardCheckBoxHelper(scoreType);
                if (scoreTypes.Contains(scoreType.ScoreName))
                    scoreCardCheckBoxHelper.Checked = true;
                this.ScoreCardCheckBoxHelperList.Add(scoreCardCheckBoxHelper);
            }
        }
    }


    public void PopulateCheckBoxsToScores()
    {
        this.MainAnswerInstance.Score = string.Empty;
        var scoreType = this.ScoreCardCheckBoxHelperList.Where(x => x.Checked)
                              .Select<ScoreCardCheckBoxHelper, string>(x => x.ScoreName)
                              .AsEnumerable();
        this.MainAnswerInstance.Score = string.Join(", ", scoreType);
    }


    public class ScoreCardCheckBoxHelper : Models.Score
    {
        public bool Checked { get; set; }

        public ScoreCardCheckBoxHelper() : base() { }

        public ScoreCardCheckBoxHelper(Models.Score score)
        {
            this.ScoreID = score.ScoreID;
            this.ScoreName = score.ScoreName;
        }
    }



}

如您所见,我正在为 MainQuestions 调用 ICollection,但我不确定如何填充问题。它们还必须基于 sectionID 进行填充。

2012 年 9 月 21 日 2:51 修订

或者,如果我显示问题列表然后在回答时将更新答案表而不是当前显示的表,我将如何将两者联系起来。

4

0 回答 0