You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ea0a32a
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.SpaServices/README.md
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,34 @@ If you try running your app now, you should see the HTML snippet generated by yo
81
81
82
82
As you can see, your JavaScript code receives context information (such as the URL being requested), and returns a `Promise` so that it can asynchronously supply the markup to be injected into the page. You can put whatever logic you like here, but typically you'll want to execute a component from your Angular 2 / React / etc. application.
83
83
84
+
**Passing data from .NET code into JavaScript code**
85
+
86
+
If you want to supply additional data to the JavaScript function that performs your prerendering, you can use the `asp-prerender-data` attribute. You can give any value as long as it's JSON-serializable. Bear in mind that it will be serialized and sent as part of the remote procedure call (RPC) to Node.js, so avoid trying to pass massive amounts of data.
+'<p>Number of cookies: '+params.data.cookies.length+'</p>';
104
+
105
+
resolve({ html: result });
106
+
});
107
+
};
108
+
```
109
+
110
+
Notice that the property names are received in JavaScript-style casing (e.g., `isGoldUser`) even though they were sent in C#-style casing (e.g., `IsGoldUser`). This is because of how the JSON serialization is configured by default.
111
+
84
112
**Passing data from server-side to client-side code**
85
113
86
114
If, as well as returning HTML, you also want to pass some contextual data from your server-side code to your client-side code, you can supply a `globals` object alongside the initial `html`, e.g.:
@@ -245,7 +273,7 @@ At this stage, run `webpack` on the command line to build `wwwroot/dist/main.js`
245
273
246
274
You can now run your React code on the client by adding the following to one of your MVC views:
Copy file name to clipboardExpand all lines: src/Microsoft.AspNetCore.SpaServices/npm/aspnet-prerendering/package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "aspnet-prerendering",
3
-
"version": "1.0.1",
3
+
"version": "1.0.2",
4
4
"description": "Helpers for server-side rendering of JavaScript applications in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
0 commit comments