ajax.beginform和xVal

时间:2010-10-06 01:29:01

标签: asp.net-mvc xval

我使用Ajax.BeginForm提交表单ans xVal来强制验证

即使表单上有错误,也会发出ajax post请求的问题。我知道客户端验证工作正常,因为它显示了正确的错误消息,但是为什么它认为无论如何都可以制作ajax请求是我不明白的事情。

我甚至尝试将causesvalidation = true放在提交标签中,但表单仍在提交中。

    <% using (Ajax.BeginForm("SuggestTemp", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "Result" }))
       {%>

        <table>
         <tr>
        <td style="text-align:right">
            Title
        </td>
        <td>
            <%= Html.TextBox("Upload.Title")%>
            <%= Html.V
alidationMessage("Upload.Title")%>
        </td>
        </tr> <tr><td><%=Html.ClientSideValidation<Upload>("Upload") %></td><td></td></tr>
        <tr><td></td><td><input type = "submit" causesvalidation = "true"  value = "Suggest " class = "btn"/></td></tr> 
      </table>
      <div id = "Result"><%=ViewData["SuggestStatus"]%></div> 

1 个答案:

答案 0 :(得分:0)

尝试将$("#yourFormId").validate()添加到OnBegin参数

例如:

<%
using (Ajax.BeginForm("SuggestTemp", "yourControllerName", new{}, new AjaxOptions
{
    HttpMethod = "POST",
    OnBegin = "function(){$('#myForm').validate();}"
},
new { id = "myForm" }){ %>