I trying to post data via jQuery Ajax function in JSON format which is working fine, howerver I have bool value and using html.checkBoxFor which is always posting false even I check it. I have update code in javaScript and force change the hidden input value accordingly if its check or not and I can see in debuging that is posting true when clicked but still receiving false on controller side. In attached screen shots you can see the post correct value but not in-correct value on controller

enter image description here

enter image description here

Model Class Attribute

  [Display(Name = "Secure Entire Property")]
  [Required(ErrorMessage = "Require Information on If You Want to Secure Entire Property")]
  public bool SecureEntireProperty { get; set; }

Razor code

<div class="form-group">
   @Html.LabelFor(model => model._RentingApplicationModel.SecureEntireProperty, htmlAttributes: new { @class = "control-label col-md-2" })
 <div class="col-md-10">
    <div class="checkbox">
     @*@Html.EditorFor(model => model._RentingApplicationModel.SecureEntireProperty)*@
     @Html.CheckBoxFor(model => model._RentingApplicationModel.SecureEntireProperty, new { @id = "SecureEntirePropertyCheck" })
     @Html.ValidationMessageFor(model => model._RentingApplicationModel.SecureEntireProperty, "", new { @class = "text-danger" })
       </div>
    </div>
  </div>

JavaScript

 $("#SecureEntirePropertyCheck").click(function () {

    if ($(this).is(':checked'))
    {
        $('[name="_RentingApplicationModel.SecureEntireProperty"]:hidden').val(true);
    }
    else
    {
        $('[name="_RentingApplicationModel.SecureEntireProperty"]:hidden').val(false);
    }
});

Jquery Ajax Method Where I am Posting

 $.ajax({
        url: formURL,
        type: "POST",
        dataType: "application/json",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({ TenentJSONList: AdditionalTenentList, ApplicationModelData: $("#CreateStudentRentingApplicationForm").serializeObject() }),
    }).done(function (data, textStatus, jqXHR) {
        //....my rest of code 

Related posts

Recent Viewed