View Full Version : Controller action might return JSON or HTML

6 Apr 2011, 6:32 AM
I have the following situation. I have an ExtJs Formpanel and I have server-side validation using IErrorDataInfo. Works perfectly. If something goes wrong a JSON string is sent to the client:

return Json(new { success = false, errors = ModelState.ToDictionary() });

The formpanel shows error messages perfectly!

Now if everything goes all right I simply want to redirect the user to a different view. That view, however, is pumped to the client while it expects a JSON string and that leads to exception.

If the client expects a JSON string, is there a possible way to enforce just a redirection to a certain view? In the controller I know what I must send, either JSON on error or a different view on success.

6 Apr 2011, 6:42 AM
Please do not double post. I have deleted the other duplicate post.

8 Apr 2011, 10:46 AM
A default FormPanel load/submit is Ajax-based. Once in the context of an Ajax call, the response is expected to be handled by the caller (the form, in your case).

As a hack, in the success() handler of the form, you could examine the JSON response, and selectively call a full page submit like so:

window.location = 'someUrl.action?someParam=blah&someOtherParam=blah2'