usefulBee usefulBee - 3 months ago 14
jQuery Question

Does Html.BeginForm have OnSuccess Event

Often I use @Ajax.ActionLink then setup AjaxOptions or use regular JQuery Ajax function to check for success. This question is specific to the following format:

using (Html.BeginForm("DoSomeAction", "ControllerName"))
{
<button>Submit</button>
}


How to check appropriately for the success of this call??

Answer

No. Html.BeginForm renders a normal form tag without any ajaxified form submit behavior. So when you click the submit button, It submits the form to the server. Browser will handle the response from the server ( show the content/ redirect to a new GET action etc)

How to check appropriately for the success of this call??

This depends on what you want to do. If you want to execute some sever code, you can do that in the HttpPost action method to which the form data is submitted.

If you want to do something on the client side, you can send some flag( may be a querystring /a hidden input field value) to the client and let your client side javascript code checks this value and do whatever needed to do. You can do this check in the document ready(assuming you have jQuery included in your page)/page load event.