HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
if (StuEdit == null) //it displays an empty view on the web browser { return HttpNotFound(); }
using LinkViewStudentDb.Models; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Mvc; namespace LinkViewStudentDb.Controllers { public class HomrController : Controller { // // GET: /Homr/ UserDb us = new UserDb(); public ActionResult Index() { return View(); } public ActionResult ViewAllStu() { UserDb us = new UserDb(); var stuCol = us.Students.Select(st => st); return View(stuCol); } public ActionResult create() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult create(FormCollection form) { var StuCre = new Student(); TryUpdateModel(StuCre, form.ToValueProvider()); if (ModelState.IsValid) { us.Students.Add(StuCre); us.SaveChanges(); return RedirectToAction("Index"); } return View(StuCre); } public ActionResult edit(string id = null) { Student StuEdit = us.Students.Find(id); if (StuEdit == null) { return HttpNotFound(); } return View(StuEdit); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult edit([Bind(Include = "StuID, name, Surname, age,sex")]Student StuEdit) { TryUpdateModel(StuEdit); if (ModelState.IsValid) { us.Entry(StuEdit).State = EntityState.Modified; us.SaveChanges(); return RedirectToAction("Index"); } return View(StuEdit); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)