ajax.beginform 和 xVal

发布于 2024-09-26 10:06:02 字数 1056 浏览 2 评论 0原文

我正在使用 Ajax.BeginForm 提交表单并使用 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> 

I am using Ajax.BeginForm to submit a form ans xVal to enforce validation

The problem the ajax post request is being made even when the form has errors on it. I know client-side validation is working, because it is displaying proper error messages and what not, but why it thinks it is okay to make the ajax request anyway is something I don't understand.

I even tried putting causesvalidation = true inside the submit tab, but the form is still being submitted.

    <% 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> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2024-10-03 10:06:02

尝试将 $("#yourFormId").validate() 放入 OnBegin 参数中,

例如:

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

try to put $("#yourFormId").validate() to the OnBegin parameter

Ex:

<%
using (Ajax.BeginForm("SuggestTemp", "yourControllerName", new{}, new AjaxOptions
{
    HttpMethod = "POST",
    OnBegin = "function(){$('#myForm').validate();}"
},
new { id = "myForm" }){ %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文