Как я уже сказал в своем комментарии, нет стандартного помощника по тегам, который генерирует div (или, во всяком случае, я не смотрел последний раз).Вот пример помощника по тегам, который мы написали в моем офисе для создания div:
[HtmlTargetElement("div", Attributes = FOR_ATTRIBUTE_NAME)]
public class DivTagHelper : TagHelper
{
private const string FOR_ATTRIBUTE_NAME = "si-for";
/// <summary>
/// Creates a new <see cref="DivTagHelper"/>.
/// </summary>
/// <param name="generator">The <see cref="IHtmlGenerator"/>.</param>
public DivTagHelper(IHtmlGenerator generator)
{
Generator = generator;
}
[HtmlAttributeNotBound]
[ViewContext]
public ViewContext ViewContext { get; set; }
protected IHtmlGenerator Generator { get; }
/// <summary>
/// An expression to be evaluated against the current model.
/// </summary>
[HtmlAttributeName(FOR_ATTRIBUTE_NAME)]
public ModelExpression For { get; set; }
/// <inheritdoc />
/// <remarks>Does nothing if <see cref="For"/> is <c>null</c>.</remarks>
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = output.Content.IsModified ? output.Content.GetContent() :
(await output.GetChildContentAsync()).GetContent();
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
output.TagName = "div";
string content;
if (For.Metadata.UnderlyingOrModelType == typeof(bool))
{
content = ((bool?) For.Model).ToYesNo();
}
else
{
var displayFormatString = For.ModelExplorer.Metadata.DisplayFormatString;
content = string.IsNullOrEmpty(displayFormatString)
? For.Model?.ToString()
: string.Format(displayFormatString, For.Model);
}
// Honour the model's specified format if there is one.
output.Content.SetContent(content);
output.PostContent.SetHtmlContent(childContent);
}
}
Вот пример использования:
<li class="TypeFile">
<si-label si-for="FileSize"></si-label>
<div si-for="FileSize" id="FileSize" class="ReadOnlyValue"></div>
<input class="subForm" asp-for="FileSizeInBytes" />
</li>
Обратите внимание, что префиксы "si" - это нашиинициалы компании, чтобы не допустить двусмысленности с существующими атрибутами.
Вот пример выходных данных:
<li class="TypeFile">
<label for="FileSize">File Size:</label>
<div id="FileSize" class="ReadOnlyValue">13.700KB</div>
<input class="subForm" type="hidden" id="FileSizeInBytes" name="FileSizeInBytes" value="14029" />
</li>