Use Razor/CSHTML page instead of static HTML
Is it possible to leverage a CSHTML Razor page as the HTML source of a component?
This would be instead of the static HTML file associated with the component by default.
By "component", do you mean an Angular/React component? If so no, that's not possible, because these components get compiled at build time into a static .js file, so there's no way of running .NET code inside it.
Hi Steve. Not what I mean.
For Angular I want to to point my template url source to an ASP.NET route (/angular/page1) and it to render that "View" as the HTML for the component. I know this was possible in AngularJS
https://stackoverflow.com/questions/25785579/is-angular-routing-template-url-support-for-cshtml-file-in-asp-net-mvc-5-projec
Thanks!
Yes, that's exactly what I thought you meant! And no, I'm afraid Angular 2+ is completely different, in that it's not loading templates as strings from HTTP requests at runtime.
It might be possible to hook into Angular 2 somehow to make it do this, but it's not something I've tried, and would certainly give up on the benefits of AoT compilation.
Ah... appreciate the response. Sure would be lovely to have that server side power at run time :)
Hi, since I am trying the same thing now, have you found a way-around? Or what further steps will you take @aherrick ? Appreciate your response!
Abandoned this approach unfortunately. Not sure if things are any different with the 2.0 release (my guess is not)
I think the compilation process of angular 2+ is different because angular cli needs the template (as html string) or templateUrl instead to render the component. To add the razor side render power to angular (as optional) should be a nice feature in the future.
I'm not sure, but if you compile your angular application and after compiling you replace your templateUrl property value for a valid razor page (including the page and it's controller), does it works?
Is this still not possible with Angular 6?