ASP.Net MVC Ajax form with jQuery validation

前端 未结 1 1186
失恋的感觉
失恋的感觉 2020-12-07 15:53

I have an MVC view with a form built with the Ajax.BeginForm() helper method, and I\'m trying to validate user input with the jQuery Validation plugin. I get the plugin to h

相关标签:
1条回答
  • 2020-12-07 16:30

    Try adding an OnBegin callback to the AjaxOptions and return the value of $('form').validate().form() from the callback. Looking at the source it appears that this should work.

    function ajaxValidate() {
       return $('form').validate().form();
    }
    
    <% using (Ajax.BeginForm("Post", new AjaxOptions
           {
               UpdateTargetId = "GBPostList",
               InsertionMode = InsertionMode.InsertBefore,
               OnBegin = "ajaxValidate",
               OnSuccess = "getGbPostSuccess",
               OnFailure = "showFaliure"
           }))
           { %>
    

    EDIT updated with correct callback name.

    0 讨论(0)
提交回复
热议问题