I'm struggling with the following:
I have a class 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; }
}
and another class 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; }
}
I want a user to be able to add a question with one or more answers from the same view. I am a newbie and not able to figure this out. At this moment I only have the possibility to create a question linked to a category in the Create view.
This is the QuestionController
:
// GET: Questions/Create
public IActionResult Create()
{
ViewData["CategoryID"] = new SelectList(_context.Category, "CategoryID", "CategoryName");
return View();
}
Thanks for your help!