Render another view's index within a create/update form view

I have an index that call a typical create/update view.

Within these, the _form uses bootstrap Tabs, the 1st one renders the views ActiveForm, but on the 2nd tab I need to render the index for another related view.

As such, I used

this->render(…)

and it does display.

My issue is if I try to filter the data, no matter what I try in save the main form and closes, or render the main form on the 2nd tab instead of reloading the referenced index view. How do I get pjax to work with the 2nd view?

Hi,
Have you tried using redirect instead of render? Because render will display the view, but maybe you’re missing some data provided by the controller. So if you call the second actionIndex using redirect it will load the needed data and, after that, render the second index view. Without seeing your code, that’s the first thing I would try.
Regards!

I can post any code you want, I just did not want to inundate the initial post with a ton of code.

I’ll give that a try and post back.

No prob. Just try instead of calling directly the view like this:
$this->render(‘otherControllerView’, [$params])
Try calling the action in the other controller, like:
$this->redirect([otherController/action, $params])

It gives me a

Calling unknown method: yii\web\View::redirect()

I tried using

Yii::$app->response->redirect(Url::to(['site/view'], true));

Yii::$app->response->redirect('site/view', 302, false);

but then it replaces the content completely with the redirected controller view which isn’t what I want.

I’m wanting the Create/Update view as normally displayed and then on another tab I want to display the index view of another controller.

I’m testing

$controller = Yii::$app->createController(‘controller-name/action-name’)[0];
$controller->runAction(‘action-name’, [‘renderPartial’ => true])

It appears to be working but I have to do some serious testing to be 100% sure this is the correct approach to use.

I assume your Pjax wrapper is only around the GridView in 2nd tab? If so, also disable url update after Pjax response upon filtering.

Submit button on main form should not be an issue if Pjax behavior is contained to 2nd view.

Your last post using Yii::$app feels a bit hacky and should not be necessary if your tabs are configured properly using either content or url as needed. I see no context needing a redirect unless I am missing something. Perhaps a mention of the use case or similar example would help understand your issue better.

For instance, initial list view is Students then opens Student record in tab 1 with Courses in tab 2.

Basically, I have an index of members (people) and you view one it open in modal the member create/update view. In that view I have 2 tabs, 1 for the member information … and another where I want to display the member’s notes index (another controller/model/view) and allow for another modal for note CRUD operations. At least, that’s the goal. The above works, but I’d love to learn and improve if there is a better way to do things!

I had it working, I believe, but know I can’t get the pjax to work from the 2nd modal form.