-1

if email exist by function check i want display error

how i do it?

 [RequiredIf(BL.datafuncs.checkIfExist(email) == true, ErrorMessage = "email already exist")]

 public string email { get; set; }
david
  • 57
  • 2
  • 8
  • What are you trying to do here? Sound like you want a `[Remote]` attribute that checks if an email already exists in the database and display error if it does. That's not what `[RequiredIf]` is for –  Oct 29 '14 at 00:12

2 Answers2

2

The RequiredIf attribute is for validating a property that is required based on the value of another property. For example if you model contains properties bool NotifyMeByEmail and string EmailAddess then you could apply it as follows.

public bool NotifyMeByEmail { get; set; }

[RequiredIf("NotifyMeByEmail", ErrorMessage = "Please enter you email address")]
public string EmailAddress { get; set; }

Then in the view, if the checkbox for NotifyMeByEmail is not checked, a validation error is generated for EmailAddress.

It looks like you actually want to validate the the email enter by the user does not already exist in he database, in which case you need a [Remote] attribute (standard MVC, not foolproof). How to: Implement Remote Validation in ASP.NET MVC

Chun Lin
  • 534
  • 14
  • 34
0

Custom attributes are embedded in the assembly, they are not run time stuff, so you can NEVER put a function inside the attribute argument. I would suggest you do the check in your controller call and perform some action accordingly

Steve
  • 11,696
  • 7
  • 43
  • 81