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();
0 Comment(s)