数据注释验证错误消息立即显示。 EF 4.2/MVC3

发布于 2024-12-28 12:09:46 字数 1139 浏览 2 评论 0原文

即使控件中有数据,我所需的数据注释消息也会立即显示在编辑表单中,但我遇到了问题。如果我单击保存一切工作正常,如果我将焦点集中到显示错误的控件,然后将焦点更改到另一个控件,错误消息就会消失...这似乎只是我的编辑表单中的问题,而创建则不然没有同样的问题。

我将 EF 4.2 与 dbcontext 生成器结合使用,并通过元数据类使用验证数据注释。我的类使用metadataType 属性指向元数据类。下面的类:

<MetadataType(GetType(PersonsMetaData))>
Partial Public Class Persons
End Class

Public Class PersonsMetaData

  Private mPersonFirstName As Object
  Private mPersonLastName As Object
  Private mPersonPrimaryEmail As Object

<Required()> _
Public Property PersonFirstName As Object
    Get
        Return mPersonFirstName
    End Get
    Set(value As Object)
        mPersonFirstName = value
    End Set
End Property

<Required()> _
Public Property PersonLastName As Object
    Get
        Return mPersonLastName
    End Get
    Set(value As Object)
        mPersonLastName = value
    End Set
End Property

<Required()> _
Public Property PersonPrimaryEmail As Object
    Get
        Return mPersonPrimaryEmail
    End Get
    Set(value As Object)
        mPersonPrimaryEmail = value
    End Set
End Property

End Class

我的编辑视图是使用 mvc 3 框架生成的。

任何建议将不胜感激

I'm having an issue with my required data annotations messages showing up right away in my edit form even though there is data in the controls. If I click save everything works fine and if I give focus to the controls that have the error displayed and then change focus to another control the error message goes away... This seems only to be the issue in my edit form, create doesn't have the same issue.

I'm using EF 4.2 with the dbcontext generator and using the validation data annotations via a metadata class. My class points to the metadata class using the metadataType attribute. class below:

<MetadataType(GetType(PersonsMetaData))>
Partial Public Class Persons
End Class

Public Class PersonsMetaData

  Private mPersonFirstName As Object
  Private mPersonLastName As Object
  Private mPersonPrimaryEmail As Object

<Required()> _
Public Property PersonFirstName As Object
    Get
        Return mPersonFirstName
    End Get
    Set(value As Object)
        mPersonFirstName = value
    End Set
End Property

<Required()> _
Public Property PersonLastName As Object
    Get
        Return mPersonLastName
    End Get
    Set(value As Object)
        mPersonLastName = value
    End Set
End Property

<Required()> _
Public Property PersonPrimaryEmail As Object
    Get
        Return mPersonPrimaryEmail
    End Get
    Set(value As Object)
        mPersonPrimaryEmail = value
    End Set
End Property

End Class

My edit view has be generated using the mvc 3 framework.

Any advice would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文