asp.net-mvc - 将列表项分配给模型属性
问题描述
模型
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 个选项
解决方案
推荐阅读
- image - 训练、测试和标记单独的文件夹
- javascript - 我想通过使用脚本来避免谷歌表格中的重复日期
- python - 我哪里做错了?(我是初学者),我该如何做对?
- python - Python - 如何在不使用堆栈和类的情况下检查有向无环图?
- python - 如何使用python在数据框中查找带有空格的行?
- python - 我想使用 pyglet 在新窗口中显示五个数字
- python - Python 分析计算机视觉输出
- autocomplete - 是否有任何具有自动完成功能的 Gauge 网络编辑器?
- talend - 如何在 Talend Open Studio for Data Quality 中根据组合在一起的两列查找重复记录?
- python - TypeError: unhashable type: 'list' for mlb