Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# *已解决*将包含更新模型对象的列表从视图返回到控制器_C#_Html_Asp.net_Asp.net Mvc_Asp.net Core - Fatal编程技术网

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");
}