mercredi 16 novembre 2016

how to post checkbox value when disabled

I tried to put readonly property for checkbox,but it is allowing user to check/uncheck the field.

Later i tried to put disable which is preventing user from check/uncheck.

But when i tried to submit form,the checkbox with disbaled value is not passing to MVC controller.

I tried to put hidden value,and tried to set value when changed but not able to pass the value to controller.

Here is my Code:

  <div  style="width:200px">@Html.CheckBoxFor(m => m.In, new { id = "cbIn", style = "vertical-align:middle;", data_bind = "checked:In,disable:useSettings" })</div>
   @Html.HiddenFor(m=>m.In,new { id = "hiddenIn" })

JQuery Code:

 $("#hiddenIn").val(data.In);

function SaveSettings() {
        try {

            var saveSettingsUrl = "/Settings/SaveSettings";
            var serializedForm = $("input,select").serialize();

            $.ajax({
                type: 'POST',
                url: saveSettingsUrl,
                async: true,
                data: serializedForm,
                success: function (data, textStatus, request) {

                    data = null;

                },
                error: function (request, status, error) {
                    handleException(request.responseText);
                }
            });
        }
        catch (error) {
            showExceptionWindow('Jquery Error:' + error);
        }
    }

How can i send the checkbox value,even when it is disabled in form post.




Aucun commentaire:

Enregistrer un commentaire