C# *已解决*将包含更新模型对象的列表从视图返回到控制器
我有一个从控制器发送到视图的模型对象列表,请参见下面的代码:C# *已解决*将包含更新模型对象的列表从视图返回到控制器,c#,html,asp.net,asp.net-mvc,asp.net-core,C#,Html,Asp.net,Asp.net Mvc,Asp.net Core,我有一个从控制器发送到视图的模型对象列表,请参见下面的代码: [HttpGet] public IActionResult PlayingQuiz() { string category = HttpContext.Session.GetString("selection"); Debug.WriteLine(category); Parser p = new Parser(category); List<Question> quizQuest
[HttpGet]
public IActionResult PlayingQuiz()
{
string category = HttpContext.Session.GetString("selection");
Debug.WriteLine(category);
Parser p = new Parser(category);
List<Question> quizQuestions = new List<Question>();
quizQuestions.Clear();
quizQuestions = p.getQuestionList();
return View(quizQuestions);
}
最后是conroller中的HttpPost操作,我想在这里接收列表:
[HttpPost]
public IActionResult PlayingQuiz(List<Question> updatedQuestions)
{
Debug.WriteLine("--------------------------------------------");
Debug.WriteLine("SIZE: ", updatedQuestions.Count);
Debug.WriteLine(updatedQuestions[0].Question_);
Debug.WriteLine(updatedQuestions[0].playersAnswer);
return View("TotalScore");
}
[HttpPost]
公共IActionResult播放测验(列出更新的问题)
{
Debug.WriteLine(“--------------------------------------------------”);
Debug.WriteLine(“大小:”,updatedQuestions.Count);
Debug.WriteLine(updatedQuestions[0].Question_);
Debug.WriteLine(更新的问题[0].playersAnswer);
返回视图(“TotalScore”);
}
问题是我使用了foreach循环,需要使用for循环。如果我找到了解决方案,我就明白了。更常见的问题之一。谢谢你,史蒂夫,这解决了我的问题!这是一个比较常见的问题。谢谢你,史蒂夫,这解决了我的问题!
[HttpPost]
public IActionResult PlayingQuiz(List<Question> updatedQuestions)
{
Debug.WriteLine("--------------------------------------------");
Debug.WriteLine("SIZE: ", updatedQuestions.Count);
Debug.WriteLine(updatedQuestions[0].Question_);
Debug.WriteLine(updatedQuestions[0].playersAnswer);
return View("TotalScore");
}