We 开发者_C百科have a large number of MVC pages using validation annotations on our entity model and other locally defined classes, and these work fine. However I now have a page whose base class is in another (referenced) project which is not working.
Some of the anotations work ok ("DisplayName", for example) but the validation is not working at all. For example, when submitting a blank form, TryUpdateModel(object) returns True, despite their being a "Required" validator on both fields.
The "UserListInfo" class in is the referenced project. I have tried with and without the "Inherits" to no avail.
Any thoughts?
<MetadataType(GetType(UserListInfoMetaData))> _
Partial Public Class UserListInfo
Inherits [Other Project Namespace].UserListInfo
End Class
Public Class UserListInfoMetaData
<UIHint("HiddenId")> _
Public Property UserID() As Object
<DisplayName("Email Address")> _
<Required(ErrorMessage:="You must enter an Email Address")> _
<StringLength(150, ErrorMessage:="Cannot be more than 150 characters long.")> _
Public Property Username() As Object
<DisplayName("Name")> _
<Required(ErrorMessage:="You must enter a Name")> _
<StringLength(150, ErrorMessage:="Cannot be more than 150 characters long.")> _
Public Property FriendlyName() As Object
End Class
Ok, what I seem to have done wrong was to provide a fully qualified path in the "Inherits" statement. If I import the base class namespace and then use a partially qualified path from that all seems fine!
Ie...
<MetadataType(GetType(UserListInfoMetaData))> _
Partial Public Class UserListInfo
Inherits Bob.Fred.Jim.UserListInfo
End Class
Does not work, but...
Imports Bob.Fred
Class XYX
<MetadataType(GetType(UserListInfoMetaData))> _
Partial Public Class UserListInfo
Inherits Jim.UserListInfo
End Class
.
.
.
End Class
Does!
精彩评论