Ajaxsubmit And Tabs

Ok I have working code using ajax submit to capture and insert records in my db. Currently though I have to go from one models view to another to have this execute. I am trying to combine all the code and execute from a view in the first model though.

Below is my code attempting that. It is displayed as the logic flows.

In this code below I am using a tab and render partial in ModelA and then eventually call the ajaxSubmitButton from ModelB and use ModelB controller to input data into my db.

The problem that I am running into now is it always inserts a record, but instead of inputting the right record it will insert the first record that is displayed in the render partial (ItemId = 1 regardless of which Item I execute the code from).


<?php

//Model A View 

$tabs = array(

array('id' => 'tab1', 'label' => 'tab', 'content' => $this->renderPartial('/modelB/_modelBView', array('model' => $model), true)),

);


$this->widget('bootstrap.widgets.TbTabs', array(

'type' => 'tabs',

'tabs' => $tabs,

));




//_modelBView

if (!Yii::app()->user->isGuest)

$this->widget('zii.widgets.CListView', array(

    'dataProvider'=>$dataProvider,

    'itemView'=>'_view',

    'template' => '{items}}',

    )); 




//_view

echo $data->checkItem;




//ModelB

public function getCheckItem ()

{

    if (something...)

        {

            echo 'Status Good'; 

        }

    else {

        echo CHtml::ajaxSubmitButton(

                'Get Item',          

                array('/modelB/getItem'), 

                array(

                    'type'=>'POST',

                    'data' => array('ItemId' => $this->ItemId, 'Type' => $this->Type),

                    'success' => "function(){window.location='".Yii::app()->createUrl('/modelC/list') . "'}",

                )

            ); 

    }

}




//ModelB Controller

public function actionGetItem() 

{

    $connection = yii::app()->db;

    $transaction=$connection->beginTransaction();

    try 

    {   

        $connection = yii::app()->db;

        $sql = "INSERT INTO modelC (ItemId, Type)

                        VALUES(:item, :type)";

        $command=$connection->createCommand($sql);

        $command->bindValue(":item", $_POST['ItemId']);

        $command->bindValue(":type", $_POST['Type']);

        $command->execute();


        $transaction->commit();

    }

    catch(Exception $e)

    {

        $transaction->rollBack();

    }

}