How to provide warnings during validation in ASP.NET MVC?

后端 未结 5 2027
我寻月下人不归
我寻月下人不归 2020-12-12 20:52

Sometimes user input is not strictly invalid but can be considered problematic.

For example:

  • A user enters a long sentence in a single-line Name<
5条回答
  •  一个人的身影
    2020-12-12 21:02

    Here is a way to do a warning without writing any server-side code. Add the class "ignore-validation" to the desired invalid elements on form submit, and in your custom validation method return "true" if the element has this class (if it has the class it means the form was submitted once). You'll also need to remove the "ignore-validation" class from #IdOfInput on blur or change, depending upon the kind of control it is, that bit of code is not represented here:

    
    

提交回复
热议问题