0

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.

1
  • 1
    Please upload code in text instead in images. Images can't be searched and therefore aren't useful to future readers, harder to read than text. Commented Jun 4, 2021 at 11:36

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. can you guide me in details?
As per the answer provided by Bellash I would create a new class in the InventoryLogin.Models namespace for the empty partial class Tbl_Users you want to apply the metadata/data validation rules to.
0

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{}
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.