Asp.net mvc 如何使用Asp.net MVC验证列表属性是否具有最少的项数(count=N)?
我有一个视图模型,它的属性如下所示Asp.net mvc 如何使用Asp.net MVC验证列表属性是否具有最少的项数(count=N)?,asp.net-mvc,validation,binding,Asp.net Mvc,Validation,Binding,我有一个视图模型,它的属性如下所示 Property SelectedGroups() as List(of string) <table> <tr> <th>Description</th> </tr> <tr> <td> <input type="hidden" name="SelectedGroups" value="o
Property SelectedGroups() as List(of string)
<table>
<tr>
<th>Description</th>
</tr>
<tr>
<td>
<input type="hidden" name="SelectedGroups" value="one" />
description one
</td>
</tr>
<tr>
<td>
<input type="hidden" name="SelectedGroups" value="two" />
description two
</td>
</tr>
<tr>
<td>
<input type="hidden" name="SelectedGroups" value="three" />
description three
</td>
</tr>
</table>
在我看来,我有这样的东西
Property SelectedGroups() as List(of string)
<table>
<tr>
<th>Description</th>
</tr>
<tr>
<td>
<input type="hidden" name="SelectedGroups" value="one" />
description one
</td>
</tr>
<tr>
<td>
<input type="hidden" name="SelectedGroups" value="two" />
description two
</td>
</tr>
<tr>
<td>
<input type="hidden" name="SelectedGroups" value="three" />
description three
</td>
</tr>
</table>
描述
描述一
说明二
说明三
使用jquery添加和删除表行。是否有一种方法可以在SelectedGroups属性上创建一个验证属性,该属性需要列表中最少数量的项?这可以用javascript来完成,但我希望它能用javascript来完成
<% Html.EnableClientValidation()%>
<%: Html.ValidationSummary(False)%>
您必须编写一个自定义验证器。内置验证器没有那么复杂 ScottGu写了一篇关于自定义验证器的好文章: