patel.milanb
patel.milanb

Reputation: 5992

Error while using Remote Property of DataAnnotation?

I am having a problem using the remote property of the data-anotation.

I am having a model for user which stores the data:

[DataType(DataType.EmailAddress,ErrorMessage="please enter valid email")]
[DisplayName("Email Address")]
[Required(ErrorMessage = "Email is Required")]
[Remote("CheckUniqueEmail","User",ErrorMessage="An account with this email address already exists.")]
public string Email { get; set; }

and I am checking the distinct user email while creating the new one...

When I try to login with the email and password in the different controller, it still calls the Remote and checks for the unique email...

I think I have to exclude the email and password property in the Login controller - but I don't know how.

Upvotes: 0

Views: 158

Answers (3)

Erik Philips
Erik Philips

Reputation: 54638

You can also use the MetadataType to reuse the same base model and apply different validations. Example Here.

Upvotes: 1

Anton Vidishchev
Anton Vidishchev

Reputation: 1399

You should use another model for logging in at LoginController.

These validations will be used everywhere you use this model.

Upvotes: 1

David Wick
David Wick

Reputation: 7105

you need to use 2 different view models, one for creating an account and one for logging in.

Upvotes: 2

Related Questions