私の jQuery コードは、特定の状況下で ddl を非表示にします。この場合、フォームを送信した後、UpdateModel を使用しても一貫して機能しないようです。コントローラー内の私のコード:
// POST: /IllnessDetail/Edit
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(IllnessDetail ill)
{
IllnessDetailFormViewModel mfv = new IllnessDetailFormViewModel(ill);
if (ModelState.IsValid)
{
try
{
IllnessDetail sick = idr.GetLatestIllnessDetailByUsername(User.Identity.Name);
UpdateModel(sick);
idr.Save();
return RedirectToAction("Current", "IllnessDetail");
}
catch
{
ModelState.AddRuleViolations(mfv.IllnessDetail.GetRuleViolations());
}
}
return View(new IllnessDetailFormViewModel(ill));
}
私はMVCを始めたばかりで、締め切りに間に合っているので、UpdateModelがどのように機能するかについてはまだ漠然としています。デバッグにより、正しい値がアクション メソッドに渡されていることが明らかになったようです。
public ActionResult Edit(IllnessDetail ill)
そして、正しい値は次の行で sick に入れられます:
IllnessDetailFormViewModel mfv = new IllnessDetailFormViewModel(ill);
ただし、すべてが完了し、クライアントに返されると、次の値が表示されます。
sick.IdInfectiousAgent
次の値の代わりに:
ill.IdInfectiousAgent
考えられる唯一の理由は、ddlInfectiousAgent が jQuery によって隠されていることです。それとも、間違った街灯柱に吠えていますか?
アンドリュー