Hello I am using C# for this web application and I am trying to pass a object stdnt through redirectToAction. But when it refreshes and goes to index skillResults is always empty. I step through to the end of the submit and it has all the correct information but it is reset when I step through the index. Any Help would be greatly appreciated.
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);
}