似乎是自定義助手的一個很好的候選者:
public static class HtmlExtensions
{
html禁用a標簽?public static IHtmlString TextBoxFor(
this HtmlHelper htmlHelper,
Expression> ex,
object htmlAttributes,
怎么打開網絡屬性、bool disabled
)
{
var attributes = new RouteValueDictionary(htmlAttributes);
HTML5 中不再支持下面哪個元素?()。if (disabled)
{
attributes["disabled"] = "disabled";
}
如何阻止ie和各大瀏覽器默認行為。return htmlHelper.TextBoxFor(ex, attributes);
}
}
可以像這樣使用:
表單元素禁用屬性,@Html.TextBoxFor(
m => m.PracticeName,
new { style = "width:100%" },
Model.PracticeName != String.Empty
css設置a標簽禁用、)
幫助器顯然可以更進一步,因此您不需要傳遞額外的布爾值,但它會自動確定表達式的值是否等于默認值(TProperty)并且它應用disabled屬性.
另一種可能性是這樣的擴展方法:
public static class AttributesExtensions
html自定義屬性。{
public static RouteValueDictionary DisabledIf(
this object htmlAttributes,
bool disabled
)
{
var attributes = new RouteValueDictionary(htmlAttributes);
if (disabled)
{
attributes["disabled"] = "disabled";
}
return attributes;
}
}
您將使用標準TextBoxFor幫助程序:
@Html.TextBoxFor(
m => m.PracticeName,
new { style = "width:100%" }.DisabledIf(Model.PracticeName != string.Empty)
)
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态