This is my view file when i click update it has to be updated in database
myForm.attachEvent("onButtonClick", function (name, command) {
if (name == "Update" && command == "Update") {
$.ajax({
url: '/Home/Update',
data: JSON.stringify({
Id:myForm.getItemValue("Id"),
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 controller i define function for update
public JsonResult Update(int Id,string Name,int Duration,int Year,string Comments)
{
Training d = new Training();
if (d.Id == Id)
{
d.Id=Id;
d.Name = Name;
d.Duration = Duration;
d.Year = Year;
d.Comments = Comments;
}
try
{
this.dbContext.Add(d);
this.dbContext.SaveChanges();
}
catch
{
}
var str = new { st = "successfully updated" };
return Json(str, JsonRequestBehavior.AllowGet);
}