Html.DropDownList - Disabled/Readonly

前端 未结 14 921
无人共我
无人共我 2020-12-01 08:51

What option do I need to set to make a drop down box readonly when using MVCs Html.DropDownList?

I\'ve tried things like....

Html.DropDownList(\"Type         


        
14条回答
  •  误落风尘
    2020-12-01 09:25

    try with @disabled and jquery, in that way you can get the value on the Controller.

    Html.DropDownList("Types", Model.Types, new {@class = "your_class disabled", @disabled= "disabled" })
    

    Add a class called "disabled" so you can enabled by searching that class(in case of multiples disabled fields), then you can use a "setTimeout" in case of not entering controller by validation attributes

    
    

    submit button like this.

     
    

    in case of inputs, just use @readonly="readonly"

    @Html.TextBoxFor("Types",Model.Types, new { @class = "form-control", @readonly= "readonly" })
    

提交回复
热议问题