Enabling & disabling a textbox in razor view (ASP.Net MVC 3)

前端 未结 4 669
不思量自难忘°
不思量自难忘° 2020-12-06 05:24

I want to Enable or Disable a textbox based on the value (Model.CompanyNameEnabled).

The below code is not working. Please rectify.

@{
         


        
4条回答
  •  一生所求
    2020-12-06 05:45

    @{
       object displayMode = (Model.CompanyNameEnabled) ? null : new {disabled = "disabled" };
       @Html.TextBox("CompanyName", "", displayMode)
    }
    

    You should pass htmlAttribute as anonymous object, with property names = html attribute names, property values = attribute values. Your mistake was that you were passing string instead of name=value pair

提交回复
热议问题