我有一個asp.net MVC3應用程序,試圖將數據保存到MS SQL表(實體框架)。
下面是表:ASP.NET MVC JSON實體框架 - 保存數據
public class CasesProgress
{
public virtual long ID { get; set; }
public virtual long Learner_ID { get; set; }
public virtual long Course_ID { get; set; }
public virtual long StudyCase_ID { get; set; }
public virtual long CaseList_ID { get; set; }
public virtual bool Viewed { get; set; }
}
這裏是我的控制器:
public ActionResult StoreProgress(long Learner_ID, long Course_ID, long StudyCase_ID, long CaseList_ID)
{
CasesProgress casesprogress = new CasesProgress();
casesprogress.Learner_ID = Learner_ID;
casesprogress.Course_ID = Course_ID;
casesprogress.StudyCase_ID = StudyCase_ID;
casesprogress.CaseList_ID = CaseList_ID;
casesprogress.Viewed = true;
db.CasesProgresses.AddObject(casesprogress);
db.SaveChanges();
return Json(new { success = true });
}
,這裏是我的javascript:
function StoreProgress1() {
$.ajax({
url: '/Home/StoreProgress',
type: 'POST',
data: {
LearnerID: "211",
Course_ID: "6",
StudyCase_ID: "19",
CaseList_ID: "2"
},
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert(data.success);
},
error: function() {
alert("error");
}
});
}
我遇到錯誤信息,甚至沒有去斷點我在控制器中有。任何想法,我是新來的。提前致謝。
爲什麼你正在創建這樣一個奇怪的API?爲什麼不傳遞json對象作爲方法參數? – vittore
我是編程新手,是否只是傳遞數據對象? – hncl