Last post Jun 01, 2017 02:37 PM by Dmitry Sikorsky
Jun 01, 2017 11:36 AM|NiceStepUp|LINK
I am developing "ASP.NET Core Web API" with "Angular 4". And this is my usual approach to use "Web API" template, so there are no folders such as
It was not a problem till I wanted to use Microsoft.AspNetCore.SpaServices. I am following this tutorial of
Microsoft.AspNetCore.SpaServices Server Side Prerendering and there are two important steps to use power of Microsoft.AspNetCore.SpaServices:
1. go to your Views/_ViewImports.cshtml file, and add the following line:
@addTagHelper "*, Microsoft.AspNetCore.SpaServices"
2. Choose a place in one of your MVC views where you want to prerender a SPA component. For example, open
Views/Home/Index.cshtml, and add markup like the following:
<div id="my-spa" asp-prerender-module="ClientApp/boot-server"></div>
But "Web Api" does not have "Views" folder and I cannot do above steps?
So my questions are:
1. How is it possible to use "@addTagHelper" in "ASP.NET Core Web API"?
2. If it is not possible to use "@addTagHelper" in WebApi, is there any replacement for "@addTagHelper" in "ASP.NET Web API"?
3. What should I do instead of using "@addTagHelper"?
Jun 01, 2017 12:08 PM|Dmitry Sikorsky|LINK
But how are you going to use tag helpers without the views? It doesn't have any sense. You don't need that line if you will not use tag helpers, because that line is only for registering the tag helpers from given assembly.
Jun 01, 2017 02:22 PM|NiceStepUp|LINK
so will server side rendering work without "@addTagHelper"?
Jun 01, 2017 02:37 PM|Dmitry Sikorsky|LINK
Rendering of what?
As I understand, you have API and don't use views. If you don't use views, you can't use tag helpers. If you don't use tag helpers, you don't need to register them.
Tag helper is server side thing, it runs on server. It is just generator for the HTML.