【发布时间】:2015-08-09 15:55:00
【问题描述】:
我正在尝试在 MVC 6 / ASP.Net vNext 中创建自定义标签助手 - 标签助手工作正常,但是有没有办法指定与标签一起使用的有效 asp- 属性,以便它们出现在intellisense? 例如,当在视图中添加符合条件的标签时,我希望 asp-ajax 和 asp-onsuccess 出现在 intellisense 列表中下面是我的 taghelper:
[TargetElement("form", Attributes = AjaxForm)]
public class UnobtrusiveFormTagHelper : TagHelper
{
private const string AjaxForm = "asp-ajax";
public override void Process(TagHelperContext context, TagHelperOutput output)
{
base.Process(context, output);
output.Attributes.Add("data-ajax", true);
output.Attributes.Add("data-onsuccess", context.AllAttributes["asp-onsuccess"]);
}
}
用法:
<form asp-ajax="true" asp-onsuccess="dothis();">
提前致谢
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-core-mvc tag-helpers