我正在尝试使用 C# 中的标记生成器生成输入复选框 html,但是,到处搜索并且似乎无法将禁用字段添加到其中,因为它不允许属性的值为 null 或空。
有没有其他方法可以添加没有值的属性???
var builder = new TagBuilder("input");
var checkedProp = true? "checked" : string.Empty;
var disabled = true? "disabled" : string.Empty;
builder.MergeAttribute("type", "checkbox");
builder.MergeAttribute("name", "yolo");
builder.MergeAttribute("checked", checkedProp);
builder.MergeAttribute(disabled, string.Empty); // failed here
值不能为 null 或空字符串。参数名称:key 说明:当前web请求执行过程中发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.ArgumentException:值不能为 null 或空字符串。
有没有更优雅的方法来添加没有值的属性???不想使用 if else 语句添加禁用字段