Set disable attribute based on a condition for Html.TextBoxFor

后端 未结 12 1198
清酒与你
清酒与你 2020-11-28 06:13

I want to set disable attribute based on a condition for Html.TextBoxFor in asp.net MVC like below

@Html.TextBoxFor(model => model.ExpireDate, new { style         


        
12条回答
  •  盖世英雄少女心
    2020-11-28 06:42

    I like Darin method. But quick way to solve this,

    Html.TextBox("Expiry", null, new { style = "width: 70px;", maxlength = "10", id = "expire-date", disabled = "disabled" }).ToString().Replace("disabled=\"disabled\"", (1 == 2 ? "" : "disabled=\"disabled\""))
    

提交回复
热议问题