分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

.net core 中的-----标记帮助程序

发布时间:2023-09-06 01:50责任编辑:熊小新关键词:暂无标签

 微软官方文档地址

  基本步骤:

    

    然后添加到

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

小例子:

  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(), ????????????@"\b(?:https?://)(\S+)\b", ?????????????"<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(), ????????????????@"\b(www\.)(\S+)\b", ????????????????"<a target=\"_blank\" href=\"http://$0\">$0</a>")); ?// www version ???????} ???}

可以将代码变成这样

.net core 中的-----标记帮助程序

原文地址:https://www.cnblogs.com/student-note/p/8909096.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved