Allow custom values from JS to be returned from renderToString in SpaServices #1312

Closed
opened 2025-08-09 17:19:39 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @loune on 10/15/2016

I think a useful feature would be to allow values other than the rendered html to be passed back from the renderToString JavaScript context to the .NET world. For example, the JS might provide a page title, which could then be rendered by the razor layout page. I think the ViewBag would be a good place for this data sharing.

For example, in boot-server.tsx

            resolve({
                html: renderToString(app),
                globals: { initialReduxState: store.getState() },
                viewBag: {
                    title: pageTitle
                }
            });

And in _Layout.cshtml

<html>
  <head>
    <title>@ViewBag.title</title>

Keen for thoughts and comments.

*Originally created by @loune on 10/15/2016* I think a useful feature would be to allow values other than the rendered html to be passed back from the renderToString JavaScript context to the .NET world. For example, the JS might provide a page title, which could then be rendered by the razor layout page. I think the ViewBag would be a good place for this data sharing. For example, in boot-server.tsx ``` resolve({ html: renderToString(app), globals: { initialReduxState: store.getState() }, viewBag: { title: pageTitle } }); ``` And in _Layout.cshtml ``` <html> <head> <title>@ViewBag.title</title> ``` Keen for thoughts and comments.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#1312
No description provided.