с классом моделей члена
public class Member
{
public int PersonId { get; set; }
public string Name { get; set; }
[EmailAddress]
public string Email { get; set; }
[DataType(DataType.Password)]
public string Password { get; set; }
[DataType(DataType.PhoneNumber)]
public string Telephone { get; set; }
[Display(Name="Date of Birth")]
public DateTime DateOfBirth { get; set; }
public decimal Salary { get; set; }
public string Website { get; set; }
[ ... tag-helper
Как получить входной идентификатор от Herper Asp-For Tag в другом пользовательском помощнике Tag Helper ⇐ C#
Место общения программистов C#
1738418331
Anonymous
с классом моделей члена
public class Member
{
public int PersonId { get; set; }
public string Name { get; set; }
[EmailAddress]
public string Email { get; set; }
[DataType(DataType.Password)]
public string Password { get; set; }
[DataType(DataType.PhoneNumber)]
public string Telephone { get; set; }
[Display(Name="Date of Birth")]
public DateTime DateOfBirth { get; set; }
public decimal Salary { get; set; }
[Url]
public string Website { get; set; }
[Display(Name="Send spam to me")]
public bool SendSpam { get; set; }
public int? NumberOfCats { get; set; }
public IFormFile Selfie { get; set; }
}
< /code>
и модель страницы < /p>
public class RegisterModel : PageModel
{
[BindProperty]
public Member Member { get; set; }
public void OnGet()
{
}
}
< /code>
this cshtml < /p>
Submit
< /code>
генерировать: < /p>
Submit
У меня есть пользовательский Labeltaghelper , который устанавливает содержимое тега метки в описание атрибута отображения. Эта часть работает нормально. Но мне нужно добавить атрибут тега «для», чтобы иметь значение идентификатора входного тега. Например, в meman_name в строке < /code>. Как получить значение member_name в The Custom Tag Helper для описания? Вот код Labeltaghelper :
[HtmlTargetElement("label", Attributes = DescriptionForAttributeName)]
public class LabelDescriptionTagHelper : TagHelper
{
private const string DescriptionForAttributeName = "asp-description-for";
private const string ForAttribute = "for";
///
/// Factory of StringLocalizer
///
private readonly IStringLocalizerFactory _localizerFactory;
///
/// Creates a new .
///
/// The .
/// Factory of string localizers
public LabelDescriptionTagHelper(IHtmlGenerator generator, IStringLocalizerFactory factory) =>
(Generator, _localizerFactory) = (generator, factory);
///
public override int Order => -1000;
[HtmlAttributeNotBound]
[ViewContext]
public ViewContext ViewContext { get; set; }
protected IHtmlGenerator Generator { get; }
///
/// An expression to be evaluated against the current model.
///
[HtmlAttributeName(DescriptionForAttributeName)]
public ModelExpression DescriptionFor { get; set; }
///
/// Does nothing if is null.
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
if (DescriptionFor.Metadata is DefaultModelMetadata defaultMetadata)
{
// Get the DisplayAttribute from the selected property
object attributeObject = defaultMetadata
.Attributes
.PropertyAttributes
.FirstOrDefault(attr => attr is DisplayAttribute);
if (attributeObject != null && attributeObject is DisplayAttribute displayAttribute)
{
// Actual content of the description of the property
string description = displayAttribute.Description;
if (!string.IsNullOrEmpty(description))
{
// Get the type of the parent object of the selected property
Type parentType = DescriptionFor.Metadata.ContainerType;
// Get the string localizer of the parent type by using the stirng localizer factory
IStringLocalizer localizer = _localizerFactory.Create(parentType);
// Get the description from the localizer
description = localizer[description];
}
// Set the content of the tag to the description content
output.Content.SetContent(description);
// HERE'S HERE I NEED TO SET THE ID OF THE INPUT TAG. HOW?
output.Attributes.Add(ForAttribute, DescriptionFor.Metadata.Name);
output.TagMode = TagMode.StartTagAndEndTag;
}
}
return Task.CompletedTask;
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/63255935/how-to-get-the-input-id-from-asp-for-tag-helper-in-another-custom-tag-helper[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия