Using @addTagHelper in ASP.NET Core WebAPI. ASP.NET Prerendering

一笑奈何 提交于 2019-12-24 07:26:04

问题


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:

  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:

  • How is it possible to use @addTagHelper in ASP.NET Core Web API?
  • If it is not possible to use @addTagHelper in WebApi, is there any replacement for @addTagHelper in 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!