首先你需要展示你的ApiController方法。
我假設你的方法是這樣的,
public HttpResponseMessage Put(int id)
{
var _AvailableToCall = HttpContext.Current.Request.Form["AvailableToCall"];
//I'm using HttpContext to fetch the data in the above line. You can fetch
//the bool value as your way
//Now you just need to fetch the data by personId, (here it is id).
myClass obj = contextObj.myClass().where(m=>m.personId ==
id).firstOrDefault();
obj.AvailableToCall = true;
//That's it. Now you can update it.
contextObj.Entry(obj).State = System.Data.Entity.EntityState.Modified;
contextObj.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK, new { Status = "OK",
Message = e.ToString() });
//You can return your data as your requirements or as you are writing in
//your project.
}
見這裏「contextObj」是我的上下文類的對象。而「myClass」是我想要更新/保存數據的模態類。
你可以寫「Json」返回類型來代替「HttpResponseMessage」。 乾杯......
你還沒有顯示你的控制器方法! (你從基於'personId'的數據庫中獲得對象並更新它的'AvailableToCall'屬性,然後保存它。 –