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 }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
[Feature Request] - Add an SPA View Engine that gives the ability to render the entire page instead of using Razor #182
Currently, it looks like the Razor view engine requires a layout and partial page.
It's possible to get around this somewhat by setting IgnoreBody() at the top of the _Layout and a placeholder view, but then you have to workaround the view by returning View("index", model) every time.
Do you think it needs to be a view engine, or would a custom ActionResult meet your needs? I started prototyping it as a view engine, but it seemed to offer no benefit vs an action result, and yet an action result was far simpler.
I added a sample in commit 749c7c showing how this can be done. If you want to try this in your project, copy the PrerenderResult.cs and PrerenderResultExtensions.cs into your project, then you'll be able to return this.Prerender(...); from your action methods as in this example.
The example I've given isn't specific to React but the code you've posted above should work to perform the actual calls into React. You'd just need to wrap it in a promise as per the example here (this ensures that you can do async prerendering too if you need).
What do you think? If more people ask for something like this, we could move PrerenderResult into the SpaServices package.
This is reasonable for apps that use ASPNET like a Advanced file server with some rest api feature, so any controllers and view is not really needed for them 😄
@laskoviymishka That sounds totally reasonable. If you can supply a proposed implementation and usage examples, we can definitely consider including some middleware like that!
Activity
SteveSandersonMS commentedon Jul 19, 2016
Great suggestion.
Do you think it needs to be a view engine, or would a custom
ActionResultmeet your needs? I started prototyping it as a view engine, but it seemed to offer no benefit vs an action result, and yet an action result was far simpler.I added a sample in commit
749c7cshowing how this can be done. If you want to try this in your project, copy thePrerenderResult.csandPrerenderResultExtensions.csinto your project, then you'll be able to returnthis.Prerender(...);from your action methods as in this example.The example I've given isn't specific to React but the code you've posted above should work to perform the actual calls into React. You'd just need to wrap it in a promise as per the example here (this ensures that you can do async prerendering too if you need).
What do you think? If more people ask for something like this, we could move
PrerenderResultinto the SpaServices package.antonchanshaw commentedon Jul 19, 2016
👍
laskoviymishka commentedon Jul 21, 2016
@SteveSandersonMS May be it reasonable to have something like a Middleware.
So usage be like there:
This is reasonable for apps that use ASPNET like a Advanced file server with some rest api feature, so any controllers and view is not really needed for them 😄
SteveSandersonMS commentedon Jul 26, 2016
@laskoviymishka That sounds totally reasonable. If you can supply a proposed implementation and usage examples, we can definitely consider including some middleware like that!