zoukankan      html  css  js  c++  java
  • .net core 中的-----标记帮助程序

     微软官方文档地址

      基本步骤:

        

        然后添加到

      具体编写规则请参考最上面的地址

    小例子:

      1.绑定参数

      2.根据参数选择是否显示html内容

       3.避免标记帮助程序冲突

    [HtmlTargetElement("p")]
    public class AutoLinkerHttpTagHelper : TagHelper
    {
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await output.GetChildContentAsync();
            // Find Urls in the content and replace them with their anchor tag equivalent.
            output.Content.SetHtmlContent(Regex.Replace(
                 childContent.GetContent(),
                 @"(?:https?://)(S+)",
                  "<a target="_blank" href="$0">$0</a>"));  // http link version}
        }
    }

      在加一个

        [HtmlTargetElement("p")]
        public class AutoLinkerWwwTagHelper : TagHelper
        {
            public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
            {
                var childContent = await output.GetChildContentAsync();
                // Find Urls in the content and replace them with their anchor tag equivalent.
                output.Content.SetHtmlContent(Regex.Replace(
                    childContent.GetContent(),
                     @"(www.)(S+)",
                     "<a target="_blank" href="http://$0">$0</a>"));  // www version
            }
        }

    可以将代码变成这样

  • 相关阅读:
    CSS 实现隐藏滚动条同时又可以滚动
    手机端自适应布局demo
    手机端自适应布局demo
    手机端自适应布局demo
    七个帮助你处理Web页面层布局的jQuery插件
    一笔画问题
    数组模拟邻接表
    邻接矩阵存图
    BFS 遍历图
    DFS 遍历图
  • 原文地址:https://www.cnblogs.com/student-note/p/8909096.html
Copyright © 2011-2022 走看看