Best Practice For Heavy Dialog Usage

I have a rather large application that uses JQuery dialogs for many of the create and update actions. Currently, I do a check in my controllers to determine if the request is an Ajax request and if so I render a partial form for the dialog. I also need to do a check when the POST happens to send the result.

My question is how to organize this. Specifically

  • Would you suggest using separate controller actions for the ajax create and update actions to simplify the controller code.

  • Would you suggest using separate ajax views for the form such as _ajax_form.php in addition to _form.php

Looking for advise from anyone who uses dialogs heavily and has found a good way to organize them.

Thanks in advance.

In a personal project, I created a special class to handle just this scenario. I’m hesitant to post the actual code, but I created an abstract HttpResponse class and two concrete implementations, HtmlHttpResponse and JsonHttpResponse.

The abstract class has a factory method to return an instance of one of the implementations based on whether the current request is an AJAX request or not.

In the action, the controller interacts with the response object to build up the content of the response. The response object itself is responsible for outputting data (or refreshing / redirecting) in a way that is appropriate for the request type.

It means that I can load a form in a dialog or as a standard page request and handle form submission from either without having to write any extra code.

Again, I’m not able to share the specifics at the moment as the code forms part of an Open University project that I haven’t yet submitted, but it might give you some ideas.

That sounds like what I am looking for. I will see what I can come up with…thanks for the nudge.


For update and create actions in the dialog do you utilize the iframe method I see described in posts online or are you doing partial renders? I ask because JavaScript seems to always be an issue in my dialogs.