2sxc View Does Not Have App Context When Rendered From Another App's View

55 views Asked by At

I have 2 different 2sxc apps on my site - I'll refer to them as App1 and App2. A content type in App1 uses a "String dropdown-query" field to get the GUID of an entity from App2.

Within an App1 view, I am using that GUID in a query (using App.Query) to retrieve the entity data from App2. This all works successfully; I have no trouble displaying this data.

// App1 View
...
var getPlaylist = App.Query["Get Playlist by GUID"];
getPlaylist.Params("PlaylistId", "16705");
var playlist = AsList(getPlaylist["Default"]).First(); // Returns entity data from App2

<p>@playlist.EntityTitle</p> // App2 data displays correctly

Additionally, I would like to render a view from App2 within App1, passing in the entity data from App.Query. This is almost working correctly.

@RenderPage("/portals/0/2sxc/Artifact-Library/_ResourcesDownload.cshtml", new { Content = playlist })

When the view is rendered, the entity data all displays correctly. However, additional context from App2 seems to be lost; e.g. the toolbar buttons raise an error when clicked (included below), and any references to App2's settings or resources returns empty.

Had an error talking to the server (status 400),
Message: Bad Request
Detail: Object reference not set to an instance of an object.

Is there a way I can preserve App2's context within App1's view? Or is there at least a way to make the toolbar work?

2

There are 2 answers

5
iJungleBoy On

I believe you should use the IRenderService - ideally on the Kit.Render - probably something like:

@Kit.Render.Module(pageId, moduleId)
0
iJungleBoy On

My understanding is that with the term Context you want to pass in some parameters. If that is your wish, you're in luck, because we added a data parameter in 15.07

https://docs.2sxc.org/api/dot-net/ToSic.Sxc.Services.IRenderService.html#ToSic_Sxc_Services_IRenderService_Module_System_Int32_System_Int32_System_String_System_Object_

@Kit.Render.Module(pageId, moduleId, data: new {isGreen = true })

Note that these parameters are like control parameters, so you would end up writing something like this in the child-razor:

@inherits Custom.Hybrid.Razor14
@{
  var isGreen = DynamicModel.IsGreen as bool;
}

or if you're already typed

@inherits Custom.Hybrid.Razor14
@{
  var isGreen = MyModel.Bool("IsGreen", fallback: false);
}

Note that this will be available in the razor control, but will not affect anything that listens to the url parameters, such as an underlying query.