change this line:
data: "rowID=" +id,
to this:
data: JSON.stringify({ rowID : id }),
And probably your URL
is wrong:
change this:
url: "/csc/devapp1/Hom/Update/",
to this:
url: '/Home/Update',
And it should work
Pregunta
I'm new to updating Enity Framework objects using JQuery and JSON. I created the entity objet in a console app and the update function and it works. I tried tranfering over to my web app and I can't get it to update through my web app.
Controller Code
[HttpPost]
public ActionResult Update(int rowID)
{
var keyValues = new KeyValuePair<string, object>[] {
new KeyValuePair<string, object>("QUICKFIX_ID", rowID)
};
var key = new EntityKey("CSCEntities.tbl_Quickfix_Toolbar", keyValues);
var quickfixtbl = (tbl_Quickfix_Toolbar)db.GetObjectByKey(key);
int usrcount = (int)quickfixtbl.USECOUNT_NR;
// update
usrcount = usrcount + 1;
// find the row to update using the ID
tbl_Quickfix_Toolbar quickFix = (from x in db.tbl_Quickfix_Toolbar
where x.QUICKFIX_ID == rowID
select x).First();
quickFix.USECOUNT_NR = usrcount;
db.SaveChanges();
return View();
}
and here is the JQueryfunction that calls my controller:
//Updates the use count in the List
function Update() {
$.ajax({
url: "/csc/devapp1/Home/Update",
type: 'POST',
data: "rowID=" +id,
contentType: "application/json;charset=utf-8",
success: function (data) {
alert('Details Updated Successfully');
},
error: function () {
alert('Unable to Update for the Given ID');
}
});
Please let me know what I'm doing wrong, I been going at this for weeks and can't get it to work.
Solución
change this line:
data: "rowID=" +id,
to this:
data: JSON.stringify({ rowID : id }),
And probably your URL
is wrong:
change this:
url: "/csc/devapp1/Hom/Update/",
to this:
url: '/Home/Update',
And it should work