Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MySQL
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);
        }
Posted 14-May-12 2:38am
Edited 14-May-12 3:01am
v2
Comments
Prasanna Kumari at 14-May-12 7:39am
   
if any one knows please give me idea......
Sandeep Mewara at 14-May-12 8:02am
   
What issue you are facing here? You get any error?
Prasanna Kumari at 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)

  Print Answers RSS
0 Marcin Kozub 330
1 OriginalGriff 256
2 Sergey Alexandrovich Kryukov 215
3 Praneet Nadkar 197
4 Richard MacCutchan 182
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 14 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100