// Trying to save the selected student from the dropdown //[HttpPost] //public IActionResult Index(StudentNames sn) //{ // ViewBag.Hello = "Hello World!"; // string selectedStudent = Request.Form["StudentNamesList"].ToString(); // ViewBag.SelectedStudent = selectedStudent; // return View(sn); //} public IActionResult SelectStudent(StudentNames sn) { ViewBag.SelectedStudent = sn.SelectedName; var position = sn.studentNames.IndexOf(sn.SelectedName); // NullReferenceException... ViewBag.StudentPosition = position; return(RedirectToAction("Index")); }
public IActionResult Index() { StudentNames sn = new StudentNames { studentNames = new List <string>() { "Benjamin", "Daveena", "Demitrius", "Elias", "Emily", "Franck", "Hyoil", "Kiran", "Paul", "Raphael", "Raven", "Taylor", "Thomas", "Tyler" } }; ViewBag.StudentNames = sn.studentNames; ViewBag.Students = _studentProvider.StudentList; //ViewBag.SelectedStudent = sn.SelectedName; //string selectedStudent = Request.Form["StudentNamesList"].ToString(); //ViewBag.SelectedStudent = selectedStudent; return(View(sn)); }