Ajax.BeginForm beforeSubmit event

2019-01-28 02:28发布

问题:

In MVC, is there a way to fire an onBeforeSubmit event when using Ajax.BeginForm? I'd like to validate some data on the client side and give proper feedback to the user.

回答1:

OnBegin is what you're looking for:

using (Ajax.BeginForm("Action", "Controller", 
new AjaxOptions() {
OnBegin = "alert('Replace with validation logic.')"
}))

UPDATE

Something like this:

   function onSubmitFeedbackBegin(context) {
        if (uploading > 0) {
            return false;
        }
    }