我有实现简单MVC3应用程序,我想验证控制形式,特别是DIV
//视图模型
public class NewStreamViewModel
{
public NewStreamViewModel()
{
this.Streams = new List<SelectListItem>();
this.Subjects = new List<SelectListItem>();
this.Languages = new List<SelectListItem>();
}
[Display(Name = "Language")]
[Required(ErrorMessage = "{0} is Required")]
public int? LanguageId {get;set;}
[Display(Name = "Stream")]
[Required(ErrorMessage = "{0} is Required")]
public int? StreamId {get;set;}
public int[] SubjectIds {get;set;}
public List<SelectListItem> Languages {get;set;}
public List<SelectListItem> Streams {get;set;}
public List<SelectListItem> Subjects {get;set;}
}
//View.cshtml
<div id="tab1">
@using (Html.BeginForm())
{
<table style="background: none; width: 100%;">
<tr>
<td>
Language
</td>
<td>
@Html.DropDownListFor(m=>m.LanguageId.Value,Model.Languages)
@Html.ValidationMessageFor(m=>m.LanguageId.Value)
</td>
</tr>
<tr>
<td>Stream
</td>
<td>
@Html.DropDownListFor(m => m.StreamId.Value, Model.Streams)
@Html.ValidationMessageFor(m=>m.StreamId.Value)
</td>
</tr>
<tr>
<td>Subjects
</td>
<td>
@Html.ListBoxFor(m => m.SubjectIds, Model.Subjects, new { Style = "width:300px;" })
</td>
</tr>
</table>
}
<input type="button" value="Save" id="addspan" />
</div>
<script type="text/javascript">
$(function () {
var count = 2;
$('#wrap').tabs();
$('#addspan').click(function () {
var $step = $('#tab1');
var validator = $("form").validate(); // obtain validator
var anyError = false;
var selects = $('#tab1').find('select');
selects.each(function () {
if (!validator.element(this)) { // validate every input element inside this step
anyError = true;
}
});
if (anyError) {
return false;
}
count++;
});
});
</script>
我怎么可以在jQuery验证在客户端这些下拉菜单?