问题
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 Views.
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 Microsoft.AspNetCore.SpaServices:
go to your
Views/_ViewImports.cshtmlfile, and add the following line:@addTagHelper "*, Microsoft.AspNetCore.SpaServices"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:
- How is it possible to use
@addTagHelperinASP.NET Core Web API? - If it is not possible to use
@addTagHelperin WebApi, is there any replacement for@addTagHelperin ASP.NET Web API? - What should I do instead of using
@addTagHelper?
回答1:
Tag Helpers render custom tags within Views, if you don't have a view there is no requirement for a tag helper or View to contain it. I you need to return html, you will probably need to return that via the API and create your own code to generate Html?
来源:https://stackoverflow.com/questions/44306233/using-addtaghelper-in-asp-net-core-webapi-asp-net-prerendering