Ujjval Shukla

Ujjval Shukla

  • NA
  • 283
  • 148.9k

Does not update a record in MVC using Linq to SQL.

Jan 8 2016 4:37 AM
Hi friends i am new in MVC,

I'm working on an MVC application with LINQ TO SQL ORM.While update operation it show the error-
Object reference not set to an instance of an object.
 
Below is the Action to Update
 
public ActionResult disUpdate(Employee eid)
        {
            if (ModelState.IsValid)
            {
                
                
                 Empmaster ed1 = db.Empmasters.Where(u => u.Emp_Id == eid.EmployeeID).SingleOrDefault();
                
                 
                ed1.Category = eid.Category;
                 ed1.Emp_Name = eid.ename;
                 ed1.Father_Husband_Name = eid.fname;
                 ed1.departmet = eid.dept;
                 ed1.designation = eid.des;
                 ed1.doj = eid.doj;
                 ed1.dob = eid.dob;
                 ed1.sex = eid.sex;
                 ed1.mstatus = eid.mstatus;
                 ed1.address = eid.address;
                 ed1.status = Convert.ToChar(eid.status);
                db.SubmitChanges();
                return View("Index");
            }
            else
            {
 
                return View();
            }
        
        }
 

Answers (6)