I'm loading a "Create User" form into a modal dialog as a partial view. Within that view, I'm using the MVC helper Ajax.BeginForm, specifying InsertionMode.ReplaceWith and an UpdateTargetId set to the form itself, so the form can be submitted and it will return an updated version of itself and replace itself if more information is needed. Basically, the AJAX request is expected to return HTML.
How should I communicate other results of such an AJAX request, such as when the operation is complete and there is no HTML to return (e.g. the user was successfully created, so the modal dialog needs to be closed)?
Could I use HTTP Status Codes or Content Type headers? I'm looking for the cleanest way to accomplish this while maintaining compatibility with the existing Ajax.BeginForm method which uses Microsoft's unobtrusive AJAX. Perhaps I'd need to specify an OnComplete handler in the AjaxOptions, check the status code or content type, then cancel the default "ReplaceWith" behavior if the operation has completed and has no HTML to return.
I'm thinking along the same lines as this comment from another post: "It doesn't seem practical to test the response by examining the HTML content for an error message rather than just testing the response code." Using Http Status Codes During Form Validation