この投稿の回答で示されているように、InputTagHelperから継承するタグヘルパーを作成しました。https://stackoverflow.com/a/40489654/945651。ここでAsp.NETコアカスタム入力タグヘルパーレンダリング重複チェックボックス
コード
[HtmlTargetElement("input", Attributes = ForAttributeName)]
public class ExrInputTagHelper : InputTagHelper
{
private const string ForAttributeName = "asp-for";
[HtmlAttributeName("asp-disabled")]
public bool IsDisabled { get; set; }
public ExrInputTagHelper(IHtmlGenerator generator):base(generator)
{
}
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (IsDisabled)
{
var d = new TagHelperAttribute("disabled", "disabled");
output.Attributes.Add(d);
}
base.Process(context, output);
}
}
ですこれはその使い方です:
<input asp-for="UsingCreditCard" type="checkbox" asp-disabled="@Model.UsingACH" />
これは素晴らしい作品が、1つの明白な問題があります。入力タイプがチェックボックスの場合は、2回レンダリングされます。他のすべての入力タイプはうまく動作します。なぜこれが起こっていますか?
<input checked="checked" data-val="true" data-val-required="The UsingCreditCard field is required." id="UsingCreditCard" name="UsingCreditCard" type="checkbox" value="true">
<input checked="checked" id="UsingCreditCard" name="UsingCreditCard" type="checkbox" value="true">
ご意見をいただければ幸いです。
ありがとうございます。
ありがとうございました。これはトリックでした。迅速な対応に感謝します。 – dherrin79