1
我與NerdDinner教程晚餐編輯控件玩弄鬼混。
我得到一個FormCollection作爲參數之一,我可以在使用UpdateModel()之前修剪它中的數據。修剪()FormCollection值
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection formValues)
{
Dinner dinner = dinnerRepository.GetDinner(id);
try
{
UpdateModel(dinner);
dinnerRepository.Save();
return RedirectToAction("Details", new { id = dinner.DinnerID });
}
catch
{
foreach (var issue in dinner.GetRuleViolations())
{
ModelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
}
return View(dinner);
}
}
或者我必須通過迭代Request.Form鍵來手動執行該操作嗎?
Hanselman鏈接是http://www.hanselman.com/blog/IPrincipalUserModelBinderInASPNETMVCForEasierTesting.aspx – nikmd23 2009-06-02 15:03:13