0
我一直在閱讀幾個與此類似的問題,處理定製@Html.ValidationMessageFor
,但沒有一個涉及到我期望做的事情。ASP.net MVC 3自定義基於模型邏輯的Html.ValidationMessageFor
我正在處理的當前表單正在編輯數據庫中的用戶。在此表單中,我需要檢查輸入的電子郵件是否已被其他用戶使用。我有邏輯,但我沒有的是自定義驗證消息在頁面上出現,如果他們使用已經在使用的電子郵件。
控制器代碼:
[HttpPost]
public ActionResult EditUser(int id, EditUserModel model)
{
if (ModelState.IsValid)
{
tbl_Users editedUser = tblUsers.EditUser(id, model, HttpContext.User.Identity.Name);
tblHSDA.EditHSDAS(id, editedUser, model.hsdas, HttpContext.User.Identity.Name);
return Redirect("~/UserManage/ListActiveUsers");
}
if (tblUsers.ValidateEmailInUse(model.Email))
{
// change validation message and return View(model);
}
tbl_Users tbl_users = db.tbl_Users.SingleOrDefault(item => item.User_id == id);
ViewBag.hsdas = tblHSDA.GetHSDANameAlpha();
ViewBag.Username = tbl_users.Username;
return View(model);
}
這是不是在控制器級別呢?
優秀。感謝您的邏輯放置,這已經解決了我的問題。 – MacSalty 2013-03-04 21:36:46