Reputation: 634
I do have a MVC ASP.NET form that requires data from the user, specifically the user has nine [required] textboxes to fill with the due info and the most of the times the info of eight of those textboxes are the same so I let the user to fill all the fields of the form once and then press a duplicate button that allows the user to only specify the data of one textbox and the others eight textboxes will be filled with the data specified before...but the user is not allowed to change this duplicated info so I use jQuery
$("#idDireccion").attr("disabled", "disabled");
$("#idEvento").attr("disabled", "disabled");
$("#ddDepartamentos").attr("disabled", "disabled");
$("#ddMunicipios").attr("disabled", "disabled");
$("#idLugar").attr("disabled", "disabled");
$("#datepicker").attr("disabled", "disabled");
$("#idHoras").attr("disabled", "disabled");
$("#idPrecio").attr("disabled", "disabled");
and specify the duplicated value via ViewBag
@Html.EditorFor(model => model.lugarEvento, new { htmlAttributes = new { @class = "form-control left-border-none", @title = "especifique lugar en que impartirá el evento", @id = "idLugar", @Value = ViewBag.lugarEvento } })
I do this for the eight textboxes and it shows the info and does not let the user to change that info but when the user submits the form to the controller that handles the operations with the database doesn´t receive anything from the duplicated info(that is part of a ViewModel) all the values are null.
my question is what I have to do in order to not let the user to modify the duplicated info and still receive that duplicated info in my controller.
Upvotes: 1
Views: 1690
Reputation: 2070
Don't use the disabled attribute use the readonly attribute instead. This will send the values to the controller.
$("#idDireccion").attr('readonly', true);
$("#idEvento").attr('readonly', true);
$("#ddDepartamentos").attr('readonly', true);
$("#ddMunicipios").attr('readonly', true);
$("#idLugar").attr('readonly', true);
$("#datepicker").attr('readonly', true);
$("#idHoras").attr('readonly', true);
$("#idPrecio").attr('readonly', true);
Upvotes: 1