Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • LINQ Update in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 118
    Comment on it

    In writing the code in MVC we can use the LINQ Language Integrated Query then we use this query for interacting with the database that will make the manipulations easier and time efficient  in terms of execution and in terms of programming .

     

    First we will create model for this

     

     public enum getstatus
        {
            success, failure
        }
        public class EmployeeModel
        {
    
            public int EmpId { get; set; }
            [Required(ErrorMessage = "First Name is required")]
            public string FirstName { get; set; }
            public string MiddleName { get; set; }
            [Required(ErrorMessage = "Last Name is required")]
            public string LastName { get; set; }
            [Required(ErrorMessage = "PhoneNo is required")]
            public string PhoneNo { get; set; }
            public string Address { get; set; }
            public getstatus Status { get; set; }
            public string msg { get; set; }
        }

     

    After that  we will create a Data Context

     

     

     

    Then after doing this we will write the controller action

     

     [HttpPost]
            public JsonResult Save(EmployeeModel EmpMod)
            {
                new GridModel().Save(EmpMod);
                return Json(true);
            }

     

     

     

    Then at last we will write the code for the updation of the data into the database.

     

    
                    EmployeeDetail empdet = new EmployeeDetail();
                    empdet = DataContextObj.EmployeeDetails.Single(p => p.EmpId == EmpMod.EmpId);
                    empdet.EmpFirstName = EmpMod.FirstName;
                    empdet.EmpMiddleName = EmpMod.MiddleName;
                    empdet.EmpLastName = EmpMod.LastName;
                    DataContextObj.SubmitChanges();

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: