我不想把更多的代碼放到我的控制器中,而不是我必須的。如何使用ASP.NET MVC 2編輯WCF數據服務對象?
這作品:
//
// POST: /Duty/Edit/5
[HttpPost]
public ActionResult Edit(Duty Model)
{
Duty Attached = (from Duty d in ctx.Duties
where d.Id == Model.Id
select d).Single();
Attached.Designation = Model.Designation;
Attached.Instruction = Model.Instruction;
Attached.OccasionId = Model.OccasionId;
Attached.Summary = Model.Summary;
ctx.UpdateObject(Attached);
ctx.SaveChanges();
return RedirectToAction("Index");
}
不過,我不希望有輸入每個屬性。
這失敗:
//
// POST: /Duty/Edit/5
[HttpPost]
public ActionResult Edit(Duty Model)
{
ctx.AttachTo("Duty", Model);
ctx.UpdateObject(Model);
ctx.SaveChanges();
return RedirectToAction("Index");
}
它拋出一個System.Data.Services.Client.DataServiceClientException:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code></code>
<message xml:lang="en-US">Resource not found for the segment 'Duty'.</message>
</error>
爲什麼?如何應該我寫這個?
'...實體'不包含'AttachUpdated'的定義,也沒有擴展方法'AttachUpdated'接受可以找到'... Entities'類型的第一個參數(你是否缺少using指令或程序集引用?) – 2010-06-21 19:15:57