我有一个包含3个表的数据库:-Pro_Process _Def_Defect _Cau_Cause
我需要在create函数中创建一个验证,以查看流程代码是否已经存在。如果它确实显示错误,如果它不允许写入,为此我在控制器中使用:
' GET: PRO_PROCESS/Create
Function Create() As ActionResult
Return View()
End Function
Public Function Available_Pro(CODE_PRO As String) As JsonResult
Return Json(Not db.PRO_PROCESS.Any(Function(c) c.CODE_PRO = CODE_PRO), JsonRequestBehavior.AllowGet)
End Function
' POST: PRO_PROCESS/Create
'To protect from overposting attacks, please enable the specific properties you want to bind to, for
'more details see http://go.microsoft.com/fwlink/?LinkId=317598.
<HttpPost()>
<ValidateAntiForgeryToken()>
Function Create(<Bind(Include:="CODE_PRO,DESCRIPTION_PRO")> ByVal pRO_PROCESS As PRO_PROCESS) As ActionResult
If ModelState.IsValid Then
db.PRO_PROCESS.Add(pRO_PROCESS)
db.SaveChanges()
Return RedirectToAction("Index")
End If
Return View(pRO_PROCESS)
End Function
在Model i中有这个
Partial Public Class PRO_PROCESS <Required(ErrorMessage:="Please, enter a valid code process")> <StringLength(6, ErrorMessage:="Process code must have only {1} characters.")> <Remote("Available_Pro", "PRO_PROCESS", ErrorMessage:="The inserted Process code already exists, please try a new one")> Public Property CODE_PRO As String <Required(ErrorMessage:="Description field can't be empty!")> Public Property DESCRIPTION_PRO As String Public Overridable Property DEF_DEFECT As ICollection(Of DEF_DEFECT) = New HashSet(Of DEF_DEFECT) End Class
&#13;
事实证明,在创建功能中它完全按照我的意愿工作,但在编辑功能中它不允许我编辑记录。有谁知道如何克服这个问题?
在这里你可以看到我发生的事情的图像