在ASP.NET Core WebAPI中使用@addTagHelper. ASP.NET预呈现 [英] Using @addTagHelper in ASP.NET Core WebAPI. ASP.NET Prerendering

查看:134
本文介绍了在ASP.NET Core WebAPI中使用@addTagHelper. ASP.NET预呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用"Angular 4" 开发"ASP.NET Core Web API" .这是我使用"Web API"模板的常用方法,因此没有诸如Views之类的文件夹.

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.

在我想使用Microsoft.AspNetCore.SpaServices之前这不是问题.我正在遵循 Microsoft教程. AspNetCore.SpaServices服务器端预渲染,使用电源Microsoft.AspNetCore.SpaServices有两个重要步骤:

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. 转到您的Views/_ViewImports.cshtml文件,并添加以下行:

  1. go to your Views/_ViewImports.cshtml file, and add the following line:

@addTagHelper "*, Microsoft.AspNetCore.SpaServices"

在您的MVC视图之一中选择要预呈现SPA组件的位置.例如,打开Views/Home/Index.cshtml,然后添加如下标记:

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>

但是Web Api没有Views文件夹,我无法执行上述步骤吗?

But Web Api does not have Views folder and I cannot do above steps?

所以我的问题是:

  • 如何在ASP.NET Core Web API中使用@addTagHelper?
  • 如果无法在WebApi中使用@addTagHelper,ASP.NET Web API中是否可以替代@addTagHelper?
  • 我应该怎么做,而不要使用@addTagHelper?
  • 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?

推荐答案

标签助手在视图中呈现自定义标签,如果您没有视图,则不需要标签助手或视图包含它.我需要返回html,您可能需要通过API返回html,并创建自己的代码以生成HTML?

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?

这篇关于在ASP.NET Core WebAPI中使用@addTagHelper. ASP.NET预呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆