Helo
I design the dhtml form and displaying values from database when updating that display value they are not affecting that particular record .They are saving in new record.
My table columns are Id,Name,Duration,Year,Comments
My view file is
myForm.attachEvent("onButtonClick", function (name, command) {
if (name == "Update" && command == "Update") {
$.ajax({
url: '/Home/Update',
data: JSON.stringify({
Name: myForm.getItemValue("Name"),
Duration: myForm.getItemValue("Duration"),
Year: myForm.getItemValue("Year"),
Comments: myForm.getItemValue("Comments")
}),
cache: false,
dataType: "json",
success: function (str) {
alert(str.st);
},
type: 'POST',
contentType: 'application/json; charset=utf-8'
});
}
});
In my controller
public ActionResult Update(int Id,string Name, int Duration, int Year, string Comments)
{
Training d = new Training();
var st = (from i in dbContext.Trainings
where i.Id==Id
select i);
if (d.Id==Id)
{
d.Name = Name;
d.Duration = Duration;
d.Year = Year;
d.Comments = Comments;
}
try
{
this.dbContext.Add(d);
this.dbContext.SaveChanges();
}
catch
{
return View();
}
var str = new { st = "Successfully updated" };
return Json(str, JsonRequestBehavior.AllowGet);
}
If i was updating the operation is not successful if any one knows please help me