Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my view file when i click update it has to be updated in database
JavaScript
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
C#
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);
        }
Posted
Updated 14-May-12 2:01am
v2
Comments
Prasanna Kumari 14-May-12 7:39am    
if any one knows please give me idea......
Sandeep Mewara 14-May-12 8:02am    
What issue you are facing here? You get any error?
Prasanna Kumari 14-May-12 8:07am    
iam not getting any error just update function is not working

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900