c# - 自托管 ASP.NET Core 2.0 : TagHelper doesnt work

标签 c# asp.net-core asp.net-core-tag-helpers

我有 ASP.NET Core 2.0 网站,它托管在 .NET Core 控制台/服务中。我已经实现了一个简单的自定义 TagHelper。当我直接从 VS2017 启动 ASP.NET Core 网站时,TagHelper 工作正常。当我启动托管 asp.net 页面的 .NET Core 控制台主机时,标签助手不起作用。

我尝试在 _ViewImports.cshtml 中注册 TagHelper,并直接在 View 中注册为 self (Home/Index)。

我的自定义 TagHelper:

[HtmlTargetElement("time")]
public class TimeTagHelper : TagHelper
{
    public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
    {
        output.Content.SetHtmlContent($"<h1>{DateTime.Now.ToShortTimeString()}</h1>");
    }
}

_ViewImports.cshtml

@using SelfHosted.Website
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper SelfHosted.Website.TagHelpers.*, SelfHosted.Website

VS2017 中的 TimeTagHelper 智能感知工作正常: TimeTagHelper in Index.cshtml

密码在GitHub . TagHelper 在 SelfHosted.Website 中实现并在/Home/Index 中使用。当 SelfHosted.Website 直接启动时它工作完美。但是当我从 SelfHostes.Console 启动网站时,它不起作用。

最佳答案

好的...我找到了答案并记录在这里。

https://github.com/aspnet/Home/issues/2216#issuecomment-332751869

关于c# - 自托管 ASP.NET Core 2.0 : TagHelper doesnt work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46449354/

相关文章:

c# - 将列表序列化为 JSON

c# - 避免使用不支持序列化的类

c# - 温莎城堡 : Will my transient component be garbage collected?

c# - 我可以在 ASP.NET Core 中使用 Content Negotiation 向浏览器返回 View 并向 API 调用返回 JSON 吗?

c# - 作为标记帮助程序的 View 组件不会被调用

asp.net - 将QueryString附加到asp.net核心 anchor 帮助器标签中的href

c# - 如何以精确的时间运行函数?

asp.net-core - 如何正确使用身份服务器 4 的自省(introspection)端点?

asp.net-mvc - HTTPS SSL 连接不受信任,尽管证书很好

c# - 如何更改 TagHelpers 中 ModelExpression 的类类型?