1、先创建一个类
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace Lian.Model
{
//using Microsoft.AspNetCore.Razor.TagHelpers;安装
[HtmlTargetElement("hello")]
public class Class1:TagHelper
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "p";
output.Attributes.Add("Id",context.UniqueId);
output.PostContent.SetContent("asdfasfd");
output.PreContent.SetContent("Hello 欢迎来到.Net高级班的VIP课程;");
}
}
}
2、然后在MVC中引入类库
3、在打开_ViewImports.cshtml
4、
@using MVC_Lian
@using MVC_Lian.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *,Lian.Model(类库名)
5、最后在.cshtml中写入这个标签了