2

If I put a disabled='disabled' propertie in a TextBox with Razor, when I submit my form, the value of this TextBox isn't sent to the controller.

@using (Html.BeginForm("Principal", "Home")) {                
    <div class="form-group">                
        @Html.LabelFor(m => m.Fornecedor, new { @class = "col-sm-2 control-label" })
        <div class="col-sm-9">
             @Html.TextBox("Fornecedor", Model.Fornecedor, new { @class = "form-control", type = "text", disabled = "disabled" })                    
        </div>
    </div>
}

When submitted, the Model.Fornecedor value in controller is null, but without the disabled propertie, the value return correctlly.

Can someone help me, to put a TextBox field disabled but pass his default value to controller when the form is submitted ?

Lucas_Santos
  • 4,638
  • 17
  • 71
  • 118
  • 2
    Browsers don't send disabled form elements to the server, you can put the value into a hidden field. – Zabavsky Jun 23 '14 at 19:02
  • 3
    What's the purpose of making the text box disabled? If you just want to avoid editing it, use `readonly="readonly"` instead. – tweray Jun 23 '14 at 19:07
  • Both answers resolved my question. Thanks – Lucas_Santos Jun 23 '14 at 19:36
  • possible duplicate of [Submitting the value of a disabled input field](http://stackoverflow.com/questions/4045648/submitting-the-value-of-a-disabled-input-field) – Ibrahim Khan Jun 24 '14 at 15:27

0 Answers0