redirectToAction正在重置数组



你好,我正在为这个web应用程序使用C#,并试图通过redirectToAction传递对象stdnt。但当它刷新并进入索引skillResults时,它总是空的。我一直走到提交的末尾,它有所有正确的信息,但当我走到索引时,它会被重置。如有任何帮助,我们将不胜感激。

public IActionResult Index(Student stdnt)
{
return View(stdnt);
}
/// <summary>
/// submit student skills
/// </summary>
/// <param name="con"></param>
/// <returns></returns>
[HttpPost]
public async Task<ActionResult> submit(Student stdnt)
{
stdnt = IsValidStudent(stdnt);
if (stdnt.warning == "")
{
//initialize arrays
stdnt.skillResults = new SkillResult[9];
for(int i = 0; i < 9; i++)
{
stdnt.skillResults[i] = new SkillResult();
stdnt.skillResults[i].skill_name = "";
stdnt.skillResults[i].skill_type = "";
stdnt.skillResults[i].description = "";
stdnt.skillResults[i].importance = "";
}
stdnt.success = true;
//find skills for the three jobs listed
for (int i = 0; i < 3; i++)
{
if (!string.IsNullOrEmpty(stdnt.JobNames[i]))
{
var jobList = new List<Job>();
jobList = await getJobs(stdnt.JobNames[i]);
var jobSkills = new JobSkills();
jobSkills = await getJobSkills(jobList[i].uuid);
//find top three skills based on importance level
var importantSkills = new List<Skill>();
for (int j = 0; j < 3; j++)
{
importantSkills.Add(new Skill() { level = 0 });
}
for (int j = 0; j < jobSkills.skills.Count; j++)
{
if (jobSkills.skills[j].level > importantSkills[0].level)
{
importantSkills[0] = jobSkills.skills[j];
}
else if (jobSkills.skills[j].level > importantSkills[1].level)
{
importantSkills[1] = jobSkills.skills[j];
}
else if (jobSkills.skills[j].level > importantSkills[2].level)
{
importantSkills[2] = jobSkills.skills[j];
}
}
//set students results
for(int j = 0;j < 3; j++)
{
stdnt.skillResults[j + i * 3].skill_name = importantSkills[j].skill_name;
stdnt.skillResults[j + i * 3].skill_type = importantSkills[j].skill_type;
stdnt.skillResults[j + i * 3].description = importantSkills[j].description;
stdnt.skillResults[j + i * 3].importance = importantSkills[j].importance.ToString();
}
}
}
}
else
{
stdnt.success = false;
}
return RedirectToAction("Index", stdnt);
}

如Courtwright所述(https://stackoverflow.com/a/129361/14879818)帖子不支持重定向。

为了接收对象stdnt,您需要使用decorator[HttpGet]

相关内容

  • 没有找到相关文章

最新更新