How i do Required If validation by function in MVC5

前端 未结 2 1817
梦谈多话
梦谈多话 2021-01-17 06:08

if email exist by function check i want display error

how i do it?

 [RequiredIf(BL.datafuncs.checkIfExist(email) == true, ErrorMessage = \"email alr         


        
2条回答
  •  天涯浪人
    2021-01-17 07:04

    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

提交回复
热议问题