空项为 HTML <option> for abp-select
Empty item as HTML <option> for abp-select
在 Razor 页面中,您可以通过执行类似于此的操作为 select
指定一个空的第一项:
<select asp-for="SelectedTags" asp-items="Model.TagOptions">
<option value="">Choose a tag</option>
</select>
是否有 abp-select
标签助手的选项,例如:
<abp-select asp-for="Mentor.RegionId" asp-items="Model.Regions">
<option value="">Choose a region</option>
</abp-select>
从 ABP 4.3.0 开始是不可能的,因为 AbpSelectTagHelperService
修改了 output.Content
而没有调用和使用 output.GetChildContentAsync
.
的结果
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var innerHtml = await GetFormInputGroupAsHtmlAsync(context, output);
...
if (suppress)
{
output.SuppressOutput();
}
else
{
output.TagName = "div";
...
output.Content.SetHtmlContent(innerHtml);
}
}
protected virtual async Task<string> GetFormInputGroupAsHtmlAsync(TagHelperContext context, TagHelperOutput output)
{
var selectTag = await GetSelectTagAsync(context, output);
...
}
protected virtual async Task<TagHelperOutput> GetSelectTagAsync(TagHelperContext context, TagHelperOutput output)
{
...
var selectTagHelperOutput = await selectTagHelper.ProcessAndGetOutputAsync(GetInputAttributes(context, output), context, "select", TagMode.StartTagAndEndTag);
// selectTagHelperOutput.Content.SetHtmlContent(childContent); // Missing
...
}
参考文献:
在 Razor 页面中,您可以通过执行类似于此的操作为 select
指定一个空的第一项:
<select asp-for="SelectedTags" asp-items="Model.TagOptions">
<option value="">Choose a tag</option>
</select>
是否有 abp-select
标签助手的选项,例如:
<abp-select asp-for="Mentor.RegionId" asp-items="Model.Regions">
<option value="">Choose a region</option>
</abp-select>
从 ABP 4.3.0 开始是不可能的,因为 AbpSelectTagHelperService
修改了 output.Content
而没有调用和使用 output.GetChildContentAsync
.
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var innerHtml = await GetFormInputGroupAsHtmlAsync(context, output);
...
if (suppress)
{
output.SuppressOutput();
}
else
{
output.TagName = "div";
...
output.Content.SetHtmlContent(innerHtml);
}
}
protected virtual async Task<string> GetFormInputGroupAsHtmlAsync(TagHelperContext context, TagHelperOutput output)
{
var selectTag = await GetSelectTagAsync(context, output);
...
}
protected virtual async Task<TagHelperOutput> GetSelectTagAsync(TagHelperContext context, TagHelperOutput output)
{
...
var selectTagHelperOutput = await selectTagHelper.ProcessAndGetOutputAsync(GetInputAttributes(context, output), context, "select", TagMode.StartTagAndEndTag);
// selectTagHelperOutput.Content.SetHtmlContent(childContent); // Missing
...
}
参考文献: