首页 > 解决方案 > 将列表项分配给模型属性

问题描述

模型

    namespace CG.MyPollSurveyAdmin.Models
    {
        public class CompletePollSurvey
        {
        public long PollSurveyID { get; set; }
        public string Name { get; set; }
        public List<OptionData> Options { get; set; }
        public List<QuestionData> QuestionDetails { get; set; }
    }
    public class QuestionData
    {
        public string QuestionName { get; set; }
        public long QuestionID { get; set; }
        public int OptionID { get; set; }
        public string OptionType { get; set; }
        public string Option_1 { get; set; }
        public string Option_2 { get; set; }
        public string Option_3 { get; set; }
        public string Option_4 { get; set; }
        public string Option_5 { get; set; }
    }
}

控制器

  private List<Question> GetQuestionsById(long PollSurveyId)
        {
            MemoryStream outMemoryStream = RESTFulServiceHelper.Instance.ExecuteGetMethod(Constants.Method_GetAllQuestions, Convert.ToString(Session[Constants.NTLoginID]));

            DataContractJsonSerializer outDataContractJsonSerialize = new DataContractJsonSerializer(typeof(List<Question>));
            List<Question> lstQuestions = outDataContractJsonSerialize.ReadObject(outMemoryStream) as List<Question>;
            List<Question> question = lstQuestions.Where(p => p.PollSurveyID == PollSurveyId).ToList();
            return question;

            }
public ActionResult Help(long PollSurveyID=2)
        {
            if (Session[Constants.Session_IsAdmin] != null && Convert.ToBoolean(Session[Constants.Session_IsAdmin]))

            {
                CompletePollSurvey completePollSurvey = new CompletePollSurvey();
                List<Question> question = GetQuestionsById(Convert.ToInt64(PollSurveyID));

                return View(completePollSurvey);
            }
            else
            {
                return RedirectToAction("Login");
            }
        }

这是我的程序的模型和控制器。到目前为止,我得到了poll id=2的所有问题,但我很难从问题列表中检索元素并将其分配给模型列表元素(或列表到列表分配)。例如,我对Poll=2有 5 个问题,每个问题有 5 个选项

标签: asp.net-mvc

解决方案


推荐阅读