ASP.NET MVC的Html.BeginForm()
似乎与jQuery验证插件一起使用,但验证插件似乎不适用于我添加到页面中的表单....
这有效,
<% using (Html.BeginForm("Login", "Registration", FormMethod.Post, new { id = "Loginform" })) {%>
<fieldset>
<legend>Login</legend>
<p>
<label for="EmailId">EmailId:</label>
<%= Html.TextBox("EmailId", null, new { @class = "text_box_height_14_width_150" })%>
</p>
<div class="status"></div>
<p>
<label for="Password">Password:</label>
<%= Html.Password("Password",null, new { @class = "text_box_height_14_width_150" }) %>
</p>
<div class="status"></div>
<p>
<input type="submit" value="Login" id="login" />
</p>
</fieldset>
<% } %>
但这不起作用,
<form id="Loginform" method="post" action="Registration/Login">
<table cellpadding="0" cellspacing="0" width="100%" style="border:none;">
<tr>
<td width="12%">Email Id : </td><td width="15%">
<input id="EmailId" type="text" class="text_box_height_14_width_150
name="EmailId" /></td><td width="20%" class="status"></td>
<td width="12%">Password : <td width="15%"><input id="Password"
type="password" class="text_box_height_14_width_150 name="Password" /></td>
<td width="20%" class="status"></td>
<td width="5%"><input type="submit" value="Login" id="BtnLogin" /></td>
</tr>
</table>
</form>
我的jquery函数有这个,
$(document).ready(function() {
var validator = $("#Loginform").validate({
rules: {
EmailId: "required",
Password: {
required: true,
minlength: 6
}
},
messages: {
EmailId: "Enter your EMail ID",
Password: {
required: "Please Provide a password",
rangelength: jQuery.format("Enter at least {0} characters")
}
},
// the errorPlacement has to take the table layout into account
errorPlacement: function(error, element) {
error.appendTo(element.parent().next());
},
// set this class to error-labels to indicate valid fields
success: function(label) {
// set as text for IE
label.html(" ").addClass("checked");
}
});
});
任何建议......我错过了什么?
答案 0 :(得分:1)
第二个样本在类名后缺少结束引号。