public ActionResult create( Dept d)
        {
            var depts = db.Dept.ToList();
            SelectList deptlist1 = new SelectList(depts, "ID", "DName");
            ViewBag.DeptList = deptlist1;

             ViewBag.dname = d.DName;
             for (var i = 0; i < depts.Count(); i++)  // Check if deptartment already exist in dept entity.
             {
                 if (depts[i].DName == d.DName)
                 {
                    return RedirectToAction("DeptAlreadyExist");
                 }
             }

                if (ModelState.IsValid)
                {
                    db.Dept.Add(d);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }

             return View(d);
        }
 public ActionResult Edit( Dept d)
 {
     if (ModelState.IsValid)
     {
         db.Entry(d).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(d);
 }