Creating custom data annotation validation in MVC 3

前端 未结 4 954
说谎
说谎 2020-12-16 05:15

For instance, I have an Employee view model. When creating an employee, I want to validate the username to make sure it doesn\'t exist.

public class Employee         


        
4条回答
  •  别那么骄傲
    2020-12-16 05:36

    You can do that by extending the Attribute class calling it ValidateDuplicate. I'd avoid doing it this way because its just another place where you potentially have to make a call to a database.

提交回复
热议问题