I need to make a custom implementation for the input field, so I created the following class:
[HtmlTargetElement("input", Attributes = "tm-for", TagStructure = TagStructure.WithoutEndTag)]
public class TmInputTagHelper : InputTagHelper
{
public TmInputTagHelper(IHtmlGenerator generator) : base(generator)
{
}
[HtmlAttributeName("tm-for")]
public ModelExpression TmFor
{
get => For;
set => For = value;
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
base.Process(context, output);
string fullName = NameAndIdProvider.GetFullHtmlFieldName(ViewContext, For.Name);
if (ViewContext.ViewData.ModelState.TryGetValue(fullName, out var entry) && entry.Errors.Count > 0)
{
output.AddClass("is-invalid", HtmlEncoder.Default);
output.RemoveClass("input-validation-error", HtmlEncoder.Default);
}
}
}
However, I can't find the reference for this class: NameAndIdProvider:
string fullName = NameAndIdProvider.GetFullHtmlFieldName(ViewContext, For.Name);
I have the following usings:
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System.Text.Encodings.Web;
Well, I don't know how I can get past that anymore!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…