mvc4 サイトにフィードバック フォームがあり、フォームの検証を行いたいと考えています。私はjQuery Validation
を使用しようとし
ましたjQueryライブラリを追加して
から書きました(1つのフィールドを試すために)<script src="/Scripts/jquery.validate.min.js"></script>
<script>
$(function () {
$("#feedback-form").validate();
$("#feedback-form").validate({
rules: {
Name: {
required: true,
minlength: 2
},
},
messages: {
Name: {
required: "Please enter a username",
minlength: "Your username must consist of at least 2 characters"
},
},
});
});
</script>
そして私の形で
@using (Html.BeginForm("Feedback", "Home", FormMethod.Post, new { id = "feedback-form" }))
{
<!-- Name -->
@Html.TextBoxFor(model => model.Name, null, new { @class = "text-field" })
<a href="#" class="link1" id="submit-button" onclick="document.getElementById('feedback-form').submit()"><em><b>Send</b></em></a>
}
ブラウザ コンソールにエラーは表示されませんが、検証は機能しません。たとえば、空のフィールドで [送信] ボタンを押すと、何もメッセージを受信しません。
どうしたの?