Set disable attribute based on a condition for Html.TextBoxFor

后端 未结 12 1155
清酒与你
清酒与你 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:30

    One simple approach I have used is conditional rendering:

    @(Model.ExpireDate == null ? 
      @Html.TextBoxFor(m => m.ExpireDate, new { @disabled = "disabled" }) : 
      @Html.TextBoxFor(m => m.ExpireDate)
    )
    

提交回复
热议问题