【发布时间】:2015-03-10 11:58:52
【问题描述】:
在创建条目(比如说用户名)时,我必须对数据进行某种重复检查。我是这样做的。 (它在VB中,但不要打扰)
在控制器中:
Function CheckForDuplication(ByVal UserName As String) As JsonResult
If db.Users.Count(Function(x) x.Username.ToLower() = UserName.ToLower()) > 0 Then
Return Json(False, JsonRequestBehavior.AllowGet)
Else
Return Json(True, JsonRequestBehavior.AllowGet)
End If
End Function
在模型中:
<Remote("CheckForDuplication", "User", HttpMethod:="POST", ErrorMessage:="username not available")>
Public Property Username As String
并在视图中使用标准 JS 验证库。
它工作得很好......在创建时。问题在于,在编辑时您无法保存相同的用户名,因为客户端验证是禁止的。因为它已经存在于 DB 中。当前的“用户名”如何通过验证但其他人仍然存在。或者应该使用自定义 JS 重做并从模型中删除 [remote]。谢谢
【问题讨论】:
标签: model-view-controller editing duplication