如何编辑剃刀的标签条目不会生成属性id-Asp.net Core MVC 5



Razor通过创建一个具有属性";id"name";以及以预定义的方式执行其他操作;id";属性,并保留其他属性。这需要使用input、select和textArea标记来完成,或者,如果可能的话,使用所有在html中生成id属性的标记来完成。有人知道怎么帮我吗?

渲染前:

<input type="text" asp-for="CodigoControle" class="form-control input" placeholder=""></input>

渲染后:

<input type="text" class="form-control input" placeholder="" data-val="true" data-val-maxlength="O campo Código de Controle deve ter no máximo 15 caracteres" data-val-maxlength-max="15" id="PaisViewModel_CodigoControle" maxlength="15" name="PaisViewModel.CodigoControle" value="">

我需要的结果(没有id属性(:

<input type="text" class="form-control input" placeholder="" data-val="true" data-val-maxlength="O campo Código de Controle deve ter no máximo 15 caracteres" data-val-maxlength-max="15" maxlength="15" name="PaisViewModel.CodigoControle" value="">

定制类别:

public class CustomTagHelper : TagHelper
{        
public override void Process(TagHelperContext context, TagHelperOutput output)
{
//var attributeObjects = context.AllAttributes.ToList();
//output.TagName = "input";
//output.TagMode = TagMode.StartTagAndEndTag;

//Remover o atributo id??????
}
}

这个标记助手应该从inputselecttextarea元素中删除生成的id属性:

[HtmlTargetElement("input", Attributes = ForAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[HtmlTargetElement("select", Attributes = ForAttributeName)]
[HtmlTargetElement("select", Attributes = ItemsAttributeName)]
[HtmlTargetElement("textarea", Attributes = ForAttributeName)]
public class CustomTagHelper : TagHelper
{
private const string ForAttributeName = "asp-for";
private const string ItemsAttributeName = "asp-items";
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.Attributes.RemoveAll("id");
}
}

最新更新