I am using jquery unobtrusive ajax and MVC Ajax.Beginform() to validate a form via C# server side. I'm always replacing the form with itself.
It's all working fine, but I am wondering:
Let's say my form is triggering a "save to database" action and this action succeeded. There are no errors in the form so I don't want to post back the form to the client, but rather a JSON message that triggers a success dialog on the front end. The problem is that the form replace is always happening. How can I force it not to replace my form when I get json back from the server?
I guess what I'm asking is: how can I NOT have the div updated but just do some other code instead?
I know about onSuccess, but it is fired after the DIV replace, I want to skip the replace.
You should jQuery ajax to post the form instead of Ajax.Beginform for this kind of functionality. The point of Ajax.BeginForm is to post the form and update a given target. If you want to return either a partial view or a JSON object, you should do the page replacing and success dialog triggering with jQuery.