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