我有一个MVC视图,其中包含使用Ajax.BeginForm()辅助方法构建的表单,我正在尝试使用jQuery Validation插件验证用户输入.我得到插件以突出显示无效输入数据的输入,但尽管输入无效,表单也会发布到服务器.
如何停止此操作,并确保仅在表单验证时发布数据?
我的代码
表格:
<fieldset>
<legend>leave a message</legend>
<% using (Ajax.BeginForm("Post", new AjaxOptions
{
UpdateTargetId = "GBPostList",
InsertionMode = InsertionMode.InsertBefore,
OnSuccess = "getGbPostSuccess",
OnFailure = "showFaliure"
}))
{ %>
<div class="column" style="width: 230px;">
<p>
<label for="Post.Header">
Rubrik</label>
<%= Html.TextBox("Post.Header", null, new { @style = "width: 200px;", @class="text required" }) %></p>
<p>
<label for="Post.Post">
Meddelande</label>
<%= Html.TextArea("Post.Post", new { @style = "width: 230px; height: 120px;" }) %></p>
</div>
<p>
<input type="submit" value="OK!" /></p>
</fieldset>
Run Code Online (Sandbox Code Playgroud)
JavaScript验证:
$(document).ready(function() {
// …
Run Code Online (Sandbox Code Playgroud)