Indu Yadav

Indu Yadav

  • NA
  • 254
  • 56.3k

check my code for update operation in mvc4

Apr 17 2017 4:44 AM
 Hello
Ramesh Palanivale 
Please check my code.......... 
 
 
[HttpGet]
public ActionResult EditData(int Candidate_Id)
{
var image = context.Applications.Find(Candidate_Id);
if (image == null)
{
return new HttpNotFoundResult();
}
var model = new Application
{
Name = image.Name,
Father_Name=image.Father_Name,
Photograph=image.Photograph,
Candidate_signature=image.Candidate_signature,
Gender=image.Gender,
DOB=image.DOB,
course=image.course,
appearing_class=image.appearing_class,
Contact_No1=image.Contact_No1,
Contact_No2=image.Contact_No2,
Email_Id=image.Email_Id,
Residence=image.Residence,
Exam_center_code=image.Exam_center_code,
Category=image.Category,
Occupation_father=image.Occupation_father,
Income=image.Income,
City=image.City,
State=image.State,
Mail_Id1=image.Mail_Id1,
Mail_Id2=image.Mail_Id2,
};
return View(model);
}
[HttpPost]
[ValidateInput(false)]
public ActionResult EditData(Application model, int Candidate_Id)
{
if (ModelState.IsValid)
{
var image= context.Applications.Find(Candidate_Id);
if (image == null)
{
return new HttpNotFoundResult();
}
image.Name=model.Name;
image.Father_Name=model.Father_Name;
image.Photograph=model.Photograph;
image.Candidate_signature=model.Candidate_signature;
image.Gender=model.Gender;
image.DOB=model.DOB;
image.course=model.course;
image.appearing_class=model.appearing_class;
image.Contact_No1=model.Contact_No1;
image.Contact_No2=model.Contact_No2;
image.Email_Id=model.Email_Id;
image.Residence=model.Residence;
image.Exam_center_code=model.Exam_center_code;
image.Category=model.Category;
image.Occupation_father=model.Occupation_father;
image.Income=model.Income;
image.City=model.City;
image.State=model.State;
image.Mail_Id1=image.Mail_Id1;
image.Mail_Id2=image.Mail_Id2;
if (model.Photograph != null)
{
var imagePath = Path.GetFileName(image.Photograph);
var imageUrl = System.IO.Path.Combine(Server.MapPath("~/PICS/"), imagePath);
image.Photograph = imageUrl;
}
context.SaveChanges();
return RedirectToAction("Index");
}
return View(model);
}

Answers (3)