これは私のJSコードです:
<script type="text/javascript">
$(document).ready(function () {
$("#form").validate({
rules: {
sub: "required",
msg: "required"
}
});
});
</script>
これはスクリプトのインポートです:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
これは私のMVCフォームです:
<% using (Html.BeginForm("RepR", "Agence", FormMethod.Post, new { @class = "search_form", @id= "form"})) { %>
<%: Html.ValidationSummary(true) %>
<%: Html.Hidden("to", Model.mailc) %>
<p>
Sujet : <br />
<%: Html.TextBox("sub")%>
<%: Html.ValidationMessage("sub","Suijet est obligatoire") %>
<br />
Message : <br />
<%: Html.TextArea("msg", new { @cols = "50", @rows = "5" })%>
</p>
<input type="submit" value="Envoyer" class="button"/>
これは HTML コード ソースです。
<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.datepicker.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.core.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.widget.js" type="text/javascript"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
</head>
<body>
//html code
<script type="text/javascript">
$(document).ready(function () {
$("form").validate({
rules: {
sub: "required",
msg: "required"
}
});
});
</script>
//html code
<form action="/Agence/RepR/9" class="search_form" method="post">
<input id="to" name="to" type="hidden" value="kaouach.ahmed@gmail.com" />
<p>
Sujet : <br />
<input id="sub" name="sub" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="sub" data-valmsg-replace="false">Suijet est obligatoire</span>
<br />
Message : <br />
<textarea cols="50" id="msg" name="msg" rows="5"></textarea>
</p>
<input type="submit" value="Envoyer" class="button"/>
</form>
なぜ機能しないのか、つまり検証を行わないのか、誰か教えてもらえますか?