Client-side custom data annotation validation

前端 未结 3 453
耶瑟儿~
耶瑟儿~ 2020-12-30 15:02

I\'ve create a custom data annotation to do some validation on my view model. The problem is that it doesn\'t validate on the client-side. Here\'s my model:

         


        
相关标签:
3条回答
  • 2020-12-30 15:07

    Implementing Iclientvalidatable only adds unobtrusive attributes to generated html inputs. To enable validation on client side you must write validators that use these unobtrusive attributes to validate the inputs. Here you can find very good explanation of client and server validation in asp.net mvc 3

    0 讨论(0)
  • 2020-12-30 15:12

    A Remote Validator is what you need here is the link http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-1

    0 讨论(0)
  • 2020-12-30 15:18

    Had same issue recently. You can write:

    $.validator.addMethod('enforcetrue', function (value, element) {
        return $(element).is(":checked");
    });
    $.validator.unobtrusive.adapters.add('enforcetrue', [], function (options) {
        options.messages['enforcetrue'] = options.message;
        options.rules['enforcetrue'] = options.params;
    });
    

    Similar question here ASP.NET MVC 3 client-side validation

    0 讨论(0)
提交回复
热议问题