本文整理汇总了C#中Microsoft.AspNetCore.Razor.TagHelpers.DefaultTagHelperContent.AppendLine方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultTagHelperContent.AppendLine方法的具体用法?C# DefaultTagHelperContent.AppendLine怎么用?C# DefaultTagHelperContent.AppendLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNetCore.Razor.TagHelpers.DefaultTagHelperContent
的用法示例。
在下文中一共展示了DefaultTagHelperContent.AppendLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateGroupsAndOptions
public static IHtmlContent GenerateGroupsAndOptions(string optionLabel, IEnumerable<SelectListItem> selectList)
{
var listItemBuilder = new DefaultTagHelperContent();
// Make optionLabel the first item that gets rendered.
if (optionLabel != null)
{
listItemBuilder.AppendLine(GenerateOption(new SelectListItem
{
Text = optionLabel,
Value = string.Empty,
Selected = false
}));
}
// Group items in the SelectList if requested.
// Treat each item with Group == null as a member of a unique group
// so they are added according to the original order.
var groupedSelectList = selectList.GroupBy(item => item.Group?.GetHashCode() ?? item.GetHashCode());
foreach (var group in groupedSelectList)
{
var optGroup = group.First().Group;
if (optGroup != null)
{
var groupBuilder = new TagBuilder("optgroup");
if (optGroup.Name != null)
{
groupBuilder.MergeAttribute("label", optGroup.Name);
}
if (optGroup.Disabled)
{
groupBuilder.MergeAttribute("disabled", "disabled");
}
groupBuilder.InnerHtml.AppendLine();
foreach (var item in group)
{
groupBuilder.InnerHtml.AppendLine(GenerateOption(item));
}
listItemBuilder.AppendLine(groupBuilder);
}
else
{
foreach (var item in group)
{
listItemBuilder.AppendLine(GenerateOption(item));
}
}
}
return listItemBuilder;
}