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

后端 未结 5 2026
我寻月下人不归
我寻月下人不归 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:18

    This is just a sketch of a possible solution. There are plenty of examples of adding custom attributes (including above) so I'll skip that bit.

    It may be possible to add the use of ignore in the jQuery validator function.

    Then use

    $("form").validate({  
    ignore: ".warning-only"
    });
    

    and use the client side validator to add the 'warning-only' class after a first pass through the validator. This should then allow the form to be sent to the server.

    As I say, just a sketch, but it is something I have been researching for furture use.

提交回复
热议问题