Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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-


C#
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();
                //Empmaster ed1 = db.Empmasters.Where(e => e.Emp_Id == eid.EmployeeID).FirstOrDefault();
                 
                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();
            }
        
        }
Posted
Comments
Herman<T>.Instance 8-Jan-16 4:43am    
at which line the exception occurs?
Ujjval Shukla 8-Jan-16 5:06am    
At this Line-

ed1.Category = eid.Category;
Herman<T>.Instance 8-Jan-16 5:16am    
Have you debugged your code and checked if eid = null?
Ujjval Shukla 8-Jan-16 5:28am    
Ye eid=null.
Herman<T>.Instance 8-Jan-16 6:03am    
and that explains:
Object reference not set to an instance of an object.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900