H M Shahzad
H M Shahzad

Reputation: 1

ASP.NET MVC data annotations with partial class and Metadata type

I have applied some validation with data annotations but somehow I am missing something in the code. Here is my Model class in Model Folder: Model Class IMAGE-01

and here is my Validation Class (cs) in ViewModel Folder

Validation Class IMAGE-02

When we run the project , validation not working.

Upvotes: 0

Views: 187

Answers (2)

Bellash
Bellash

Reputation: 8204

Create Tbl_Users class in a separate file and change the namespace like this

 namespace InventoryLogin.Models {
    [MetadataType(typeof(InventoryLogin.ViewModel.LoginValidation))]
    public partial class Tbl_Users{}
 }

Upvotes: 0

PeterG
PeterG

Reputation: 162

The namespace of your partial classes for Tbl_Users are in different namespaces (InventoryLogin.Models and InventoryLogin.ViewModel).

These partial classes need to be in the same namespace for the data validation rules to be applied correctly to the class.

Upvotes: 1

Related Questions