What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 23768 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET AJAX > Database Problem my sql ...
Prasanna64

Database Problem my sql

Replies: 0 | Posted by: Prasanna64 on 5/11/2012 | Category: ASP.NET AJAX Forums | Views: 376 | Status: [Member] | Points: 10  


Hi all,

Can u tell me the code to save data from the form to the database. I had done but it is not implementing successfully in asp.net mvc3 application

I will sending my code
in controller i wrote
public ActionResult Save(string Name, int Duration, int year, string Comments)
{

var str = new { st = "This is succed" };

Menu_table m = new Menu_table();

m.Name = Name;
m.Duration = Duration;
m.Trainingyear = year;
m.Comments = Comments;


try
{
this.dbContext.Add(m);
this.dbContext.SaveChanges();
return RedirectToAction("Index");
}
catch
{

return View(str);
}

return Json(str, JsonRequestBehavior.AllowGet);
}
In my view i wrote


myForm.attachEvent("onButtonClick", function (name, command) {

if (name == "Save" && command == "Save") {

$.ajax({

url: '/Home/Save',

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'
});

}

});


}

if any one knows please help me


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

  No reply found.


Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 3:11:49 PM