我正在通過html助手和TagBuilder生成HTML文本框。如何添加沒有值的屬性
我們有方法TagBuilder.Attributes.Add(「鍵」,「值」)
但對於HTML5必需的屬性不需要值傳遞的,所以如果我通過空字符串,則具有所需值的輸出=「」
那麼如何在不傳遞值的情況下添加必需的屬性?
public static IHtmlString AppTextBox(this HtmlHelper helper, string model)
{
var input = new TagBuilder("input");
input.Attributes.Add("class", "form-control");
input.Attributes.Add("ng-model", model);
input.Attributes.Add("required","");
return new MvcHtmlString(input.ToString(TagRenderMode.Normal));
}