The solution of zac is good, i just would change its code that the layer to update, doesnt need to have any contents at first as is going to be updated before displaying the dialog.
You probably see the whole page displayed because that you point to the wrong action and on url not found your app resolves to the index page or you dont have renderPartial on your ajax response followed by a Yii::app()->end();
What happens is that the whole page (i.e. the page that calls the dialog) gets displayed in the dialog. When I don’t use AJAX (as per my original post) then only the partial view is displayed.
public function actionMyAction()
{
[...]
if(Yii::app()->request->isAjaxRequest)
$this->renderPartial('_view', array('model'=>$model));
else
$this->render('CompleteView', array('model'=>$model));
}
In such way, you will be rendering only your subview in case of ajax request.
As Antonio Ramirez stated, as in this case we are doing the ajax refresh before calling dialog, you can replace even the div #mydialog, but if you are replacing once again, you will have some problem because the CJuiDialog will generate some extra content inside the main div, so you will have to recall dialog.
I usually place an extra div inside the dialog for have something of safe to replace.
I see. That work’s for me. But how come we have to renderPartial() the same view in both the view and the controller?
Actually I took out the renderPartial() from the view file - the content is displayed through the AJAX call but the CSS formatting is not there. The content of the partial view file is a CDetailView widget. It seems that the CDetailView CSS file does not get registered, perhaps because it is being called via the controller and not the view file…
Exactly GSTAR, this is happening when you call renderPartial(). If you wish CSS formatting for your ajax calls, you should register all necessary CSS files from your main render(). Assuming that consecuent AJAX calls, will bring HTML blocks with styles already registered.
Cool, just one more question. When clicking on the link, the ‘#’ still gets put in the address bar, i.e. the ‘return false’ does not seem to be working…
I think that you need to put the return false; ‘after’ the CHtml::ajax — as in the way it is now, return false is executed within the ‘success’ callback function.