0
我是使用JQuery和JSON更新Enity Framework對象的新手。我在控制檯應用程序中創建了實體對象,並使用了更新功能,它可以工作。我嘗試轉移到我的網絡應用程序,我無法通過我的網絡應用程序更新它。MVC2使用JQuery JSON對象的更新實體框架數據庫(請幫我看看這個工作)
控制器代碼
[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();
}
這裏是調用我的控制器JQueryfunction:
//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');
}
});
請讓我知道我做錯了,我已經在這個持續數週,可以不能讓它工作。
你可以在一個值發送到您的js的網址也。所以Url會像var [email protected](「Update」,「controller」,new {[email protected]}); js.doSomething({URL = URL}); –
我更新了問題URL。我注意到我拼錯了URL * Home控制器。我使用的是JQGrid,當我嘗試使用@ Url.Action(「Update」,「Home」)時,它破壞了我的代碼。 JQGrid不再顯示。 – JEuvin
''/ Home/Update'應該可以正常工作 –