1
我遇到一些困惑與jquery.validate.jsMVC2和jquery.validate.js
首先,什麼是MicrosoftMvcJqueryValidation.js。它在網頁中被引用,但似乎已從RTM MVC2中消失,現在處於未來。我需要它嗎?
我問的原因是我試圖使用驗證與MVC,我無法得到它的工作。我將我的JS定義爲:
$(document).ready(function() {
$("#myForm").validate({
rules: {
f_fullname: { required: true },
f_email: { required: true, email: true },
f_email_c: { equalTo: "#f_email" },
f_password: { required: true, minlength: 6 },
f_password_c: { equalTo: "#f_password" }
},
messages: {
f_fullname: { required: "* required" },
f_email: { required: "* required", email: "* not a valid email address" },
f_email_c: { equalTo: "* does not match the other email" },
f_password: { required: "* required", minlength: "password must be at least 6 characters long" },
f_password_c: { equalTo: "* does not match the other email" }
}
});
});
和我對視形式:
<% using (Html.BeginForm("CreateNew", "Account", FormMethod.Post, new { id = "myForm" }))
{ %>
<fieldset>
<label for="f_fullname">name:</label><input id="f_fullname"/>
<label for="f_email"><input id="f_email"/>
...etc...
<input type="submit" value="Create" id="f_submit"/>
</fieldset>
<% } %>
和驗證方法被調用的。就緒()與螢火沒有錯誤。然而,當我提交表單時,沒有任何內容被驗證,並且表單被提交。如果我創建一個submitHandler()它會被調用,但插件沒有檢測到任何驗證錯誤(.valid()== true)
我錯過了什麼?
謝謝!是的,除了ID以外,還添加了名字。 – 2010-05-23 16:51:30