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

前端 未结 4 677
不思量自难忘°
不思量自难忘° 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 06:03

    As is already mentioned in this thread the suggested answer doesn't work in MVC5 anymore. There's actually an easy two step solution to that problem.

    1. Assign a class to the HTML inputs you want to be disabled / enabled (id will do for a single item just as fine of course). In the example below I assigned a class 'switch-disabled' to the input.
    @Html.TextBox("CompanyName", "", new { htmlAttributes = new { @class = "form-control switch-disable" } })
    
    1. Use javascript(jquery) to enable / disable the disabled parameter in HTML. In my example below I do this at the page load.
    
    

提交回复
热议问题