当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc 3 - jQuery validation for managing collection minimum (mvc3 custom ValidationAttribute)

问题描述:

The question seems simple but I cannot seem to find a solution on stackoverflow or any other source.

jQuery validation (unobstrusive) is perfect while managing fields.

However, can we check a collection length with it?

Using data- on the form for example?

Why

You may say OK but why don't you just check it with a javascript method?

The real thing is that I am using MVC3 custom data annotations to generate the validation code for me.

So it would be better to only have to set an attribute on the MVC model, and to let jQuery validate handle all the checkings and generate the errors messages in the error summary.


I've seen validation for:

  • Required objects collections
  • Custom adapters

But nothing that handles the minimum of a collection.

Is there any way to handle some kind of "collection logic?" (client side)

no field = no validation, that's the problem I have for the moment

Everything works for the server-side, but since there is no field, there's no data.

网友答案:

Quote OP:

"However, can we check a collection length with it? Using data- on the form for example?"

"no field = no validation, that's the problem I have for the moment"

The Unobtrusive Validation (powered by the jQuery Validate plugin) can only evaluate rules on the data from the following form elements: input (various types), select and textarea.

So if you're looking for a way to perform validation on some other kind of element, then it cannot be done with this plugin.

分享给朋友:
您可能感兴趣的文章:
随机阅读: