【发布时间】:2022-01-19 21:52:32
【问题描述】:
我正在努力解决以下问题:
我有一堂课Questions:
public class Question
{
public int QuestionID { get; set; }
public string QuestionText { get; set; }
public int CategoryID { get; set; }
public string Explanation { get; set; }
public virtual Category Category { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
}
还有另一个班级Answer:
public class Answer
{
public int AnswerID { get; set; }
public string AnswerText { get; set; }
public string Class { get; set; }
public int QuestionID { get; set; }
public virtual Question Question { get; set; }
}
我希望用户能够从同一视图添加一个或多个答案的问题。我是一个新手,无法弄清楚这一点。目前我只能在“创建”视图中创建一个链接到某个类别的问题。
这是QuestionController:
// GET: Questions/Create
public IActionResult Create()
{
ViewData["CategoryID"] = new SelectList(_context.Category, "CategoryID", "CategoryName");
return View();
}
感谢您的帮助!
【问题讨论】:
标签: entity-framework asp.net-core-mvc one-to-many