I have a problem to render a view in a dialog via ajax/jquery request. I have tried and solved this. I am sharing my solution.
//Text Link:
echo CHtml::link('Export', '#', array(
'onclick'=>'catchBulkId(\'exportTripData\',\'export\'); return false;',
));
// Java script:
function catchBulkId(viewFileName,dialogName){
var fields = $(":checkbox").serializeArray(); //catch all checked boxes from grid
if (fields.length == 0)
{
alert('Nothing Selected');
}else {
$('#'+dialogName+'-dialog').dialog("open");
var checkedId ="";
jQuery.each(fields, function(i, field){
checkedId = checkedId + field.value + "*";
});
jQuery.ajax({'url':'<?php echo Yii::app()->request->baseUrl; ?>/index.php/trip/'+viewFileName+'/?idlist='+checkedId,'cache':false,'success':function(html){jQuery('#'+dialogName+'-dialog').html(html)}});
}
}
/script
// The CJuiDialog:
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'export-dialog',
'options'=>array(
'title'=>'Your Title',
'width'=>500,
'height'=>250,
'autoOpen'=>false,
'resizable'=>false,
'modal'=>true,
'overlay'=>array(
'backgroundColor'=>'#000',
'opacity'=>'0.5'
),
'buttons'=>array(
'Export'=>'js:function(){ doExport(); }',
'Cancel'=>'js:function(){ $(this).dialog("close"); }',
),
),
));
In controller:
$this->renderPartial('yourViewFileName', array(), false, true);