Добрый день, подскажите, пожалуйста, как можно автоматически установить индекс в контенте в children taghelpers?
сейчас вот такая разметка, для необходимого результата в ручную приходиться устанавливать filter-index:
<filter-group>
<filter-item filter-index="0" filter-for="@Model.FirstOrDefault().Id" />
<filter-item filter-index="1" filter-for="@Model.FirstOrDefault().Article" />
<filter-item filter-index="2" filter-for="@Model.FirstOrDefault().Name" />
</filter-group>
вот такой код для хелперов:
public class ParentTagHelper : TagHelper
{
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = await output.GetChildContentAsync();
output.TagName = "form";
output.Attributes.SetAttribute("action", "/Filters/Index");
output.Content.AppendHtml(childContent);
output.PostContent.AppendHtml("<button class=\"btn btn-outline-dark\">Применить</button>");
}
}
[HtmlTargetElement("filter-item", Attributes = "filter-for", ParentTag = "filter-group")]
public class HeaderTagHelper : TagHelper
{
public ModelExpression FilterFor { get; set; }
[HtmlAttributeName("filter-index")]
public int I { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagMode = TagMode.StartTagAndEndTag;
output.TagName = "div";
output.Attributes.SetAttribute("class", "form-group");
output.Content.AppendHtml($"<input type=\"text\" name=\"Filters[{ I }].FieldName\" value=\"{ FilterFor.Name }\" class=\"form-control\" />");
}
}
Заранее благодарю за помощь.