<hgroup class="title"> <h1>@ViewBag.Title.</h1> <h2>创建新帐户。</h2> </hgroup> @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary() <fieldset class ="register"> <legend>注册表单</legend> <ol> <li> @Html.LabelFor(m => m.UserName) @Html.TextBoxFor(m => m.UserName) </li> <li> @Html.LabelFor(m => m.Password) @Html.PasswordFor(m => m.Password) </li> <li> @Html.LabelFor(m => m.ConfirmPassword) @Html.PasswordFor(m => m.ConfirmPassword) </li> </ol> <input id="btregister" type="submit" value="注册" /> </fieldset> <p id="log"> 已注册?@Html.ActionLink("登录", "Login", "Account") </p> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
用户名和密码都是用强类型的Html写的,想实现jquery客户端验证,该怎样写?
以下是我写的脚本
$("form").validate({ rules: { UserName: { required: true, minlength: 6 }, Password: { required: true, minlength: 6 }, ConfirmPassword: { required: true, minlength: 6, equalTo: "#Password" } }, messages: { UserName: { required: "请输入姓名", minlength:"用户名不能小于6个字符" }, Password: { required: "请输入密码", minlength: jQuery.format("密码不能小于{0}个字符") }, ConfirmPassword: { required: "请输入确认密码", minlength: "确认密码不能小于6个字符", equalTo: "两次输入密码不一致不一致" } } });
为什么实现不了客户端验证?
@Scripts.Render("~/bundles/jqueryval")
直接切换成路径引用呢。看你jquery.validate.js。。。等等引入没有。
果然是引用的问题,现在可以实现了。谢谢!