[英]NameAndIdProvider finds no reference in the context of the class - ASP.NET Core MVC
I need to make a custom implementation for the input field, so I created the following class:我需要对输入字段进行自定义实现,因此我创建了以下 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:但是,我找不到此 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!好吧,我不知道我怎么能再过去了!
You may use asp.net core 3 or higher, but NameAndIdProvider is an assembly below 2.2, which is the source code .您可以使用 asp.net 内核 3 或更高,但 NameAndIdProvider 是 2.2 以下的程序集,这是源代码。
The scope of Internal is limited to a certain assembly, but the assembly here is different, so it cannot be referenced. Internal的scope仅限于某个组件,但是这里的组件不同,所以不能引用。 A better way is to customize this function in current project according to above GetFullHtmlFieldName.
更好的方法是根据上面的GetFullHtmlFieldName在当前项目中自定义这个function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.