public async Task <IActionResult> Create(int id, [Bind("TestiranjeId,StudentId,RazredId,DatumTest")] Testiranje testiranje) { if (ModelState.IsValid) { var br = _context.Student .Where(c => c.StudentId == id) .Select(c => c.StudentId) .FirstOrDefault(); testiranje.StudentId = br; _context.Add(testiranje); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RazredId"] = new SelectList(_context.Razred, "RazredId", "BrojRazred", testiranje.RazredId); //ViewData["StudentId"] = new SelectList(_context.Student, "StudentId", "Ime", testiranje.StudentId); //ViewData["StudentId_Ime"] = _context.Student // .Where(c => c.StudentId == id) // .Select(c => c.Ime) // .FirstOrDefault(); //ViewData["StudentId_Prezime"] = _context.Student // .Where(c => c.StudentId == id) // .Select(c => c.Prezime) // .FirstOrDefault(); return(View(testiranje)); }
public async Task <IActionResult> Edit(int id, [Bind("TestiranjeId,StudentId,RazredId,DatumTest")] Testiranje testiranje) { if (id != testiranje.TestiranjeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(testiranje); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TestiranjeExists(testiranje.TestiranjeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["RazredId"] = new SelectList(_context.Razred, "RazredId", "BrojRazred", testiranje.RazredId); ViewData["StudentId"] = new SelectList(_context.Student, "StudentId", "Ime", testiranje.StudentId); return(View(testiranje)); }