0

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.

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
patel.milanb
  • 5,822
  • 15
  • 56
  • 92

3 Answers3

2

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

David Wick
  • 7,055
  • 2
  • 36
  • 38
1

You should use another model for logging in at LoginController.

These validations will be used everywhere you use this model.

Anton Vidishchev
  • 1,374
  • 12
  • 17
  • thanks... i dint know that these validation works everywhere ...thanks for sharing ...i got it working by creating ViewModel... – patel.milanb Sep 12 '11 at 23:36
1

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

Community
  • 1
  • 1
Erik Philips
  • 53,428
  • 11
  • 128
  • 150