index.cshtml
@section scripts{ }
index.js
$().ready(function () {$("#formLogin").validate({rules: {username: {required: true }, password: { required: true }, sex: { required: true }, level: { required: true }, favorite: { required: true } }, messages: { username: { required: "please input username" }, password: { required: "please input password" }, sex: { required: "please select sex" }, level: { required: "level requred" }, favorite: { required: "favorite required" } } , errorPlacement: function (error, element) { //指定错误信息位置 if (element.is(':radio') || element.is(':checkbox')) { //如果是radio或checkbox var eid = element.attr('name'); //获取元素的name属性 error.appendTo(element.parent()); //将错误信息添加当前元素的父结点后面 } else { error.insertAfter(element); } } }); }); $("#submit").click(function () { $("#submit").submit(); });