Angular 5 + AspNetCore + SpaServices + cshtml Can this be done?

This is a two part question...

1) About Angular 5/6 capabilities with Angular Universal and Server Side Rendering.

2) About Microsoft.AspNetCore.SpaServices and its' support for cshtml pages/injecting pre-rendered razor views into Angular.

使用Angular Universal或Angular Universal进行服务器端渲染调用cshtml页面?

The Goal

  • Merge both Angular and Asp.Net Core into one project (Not only for API use but also for server-side HTML rendering)

  • NOT use the existing Microsoft.AspNetCore.SpaTemplates Angular starter template, since it adds some extra complexity I don't need.

  • Utilize the strengths of Asp.Net Core Razor for partial view rendering & manipulation, then send the rendered HTML back to the Angular client

  • Angular Client should be able to inject the rendered HTML from the server, then continue DOM manipulation, Binding etc.

  • My Progress

    I've successfully created a basic Asp.Net Core project then manually integrated Angular.

    The steps are:

  • Create Asp.Net core project, then use the angular-cli to create a new project in the same directory " ng new MyAngularApp --minimal "

  • Manually copy the all the files from the "src" folder from the generated MyAngularApp into an Asp.Net Core new folder "ClientApp"

  • Then copy the json config files (angular-cli, package & tsconfig) into the root of your Asp.Net Project.

  • Angular 5将配置文件与asp.net核心合并

    Best Reference I found how to do this was a Pluralsight Tutorial " Building a Web App with ASP.NET Core, MVC, Entity Framework Core, Bootstrap, and Angular" by Shawn Wildermuth - https://app.pluralsight.com/library/courses/aspnetcore-mvc-efcore-bootstrap-angular-web/table-of-contents (Check out the chapter on Client-side Development with Angular) - for the record I have no affiliation with Pluralsight or Shawn

    The Problem/Question

    I understand using Node.js as a back-end with Angular Universal, but I think in the Asp.Net Core world, there is a perfectly valid case for rendering html via Razor Page.

  • Question: Can I use Microsoft.AspNetCore.SpaServices (https://github.com/aspnet/JavaScriptServices) to call a cshtml page or call the server url path, that will then render on the server then inject the HTML via the SpaService into the Angular framework.
  • Here's an example of the Angular Component 在这里输入图像描述

    链接地址: http://www.djcxy.com/p/52544.html

    上一篇: 使用Node.js vs PHP有什么好处

    下一篇: Angular 5 + AspNetCore + SpaServices + cshtml可以这样做吗?