jQuery Ajax関数を介して正常に動作しているJSON形式でデータを投稿しようとしていますが、bool値があり、チェックしても常にfalseを投稿しているhtml.checkBoxForを使用しています。私はjavaScriptでコードを更新し、それに応じて非表示の入力値を強制的に変更します. 添付のスクリーン ショットでは、コントローラーの正しい値は示されていますが、正しくない値は示されていません。
モデル クラス属性
[Display(Name = "Secure Entire Property")]
[Required(ErrorMessage = "Require Information on If You Want to Secure Entire Property")]
public bool SecureEntireProperty { get; set; }
かみそりコード
<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メソッド
$.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
追加のテナント リスト
<script type="text/javascript">
var AdditionalTenentList = new Array();
$(".additionalTententUWLID").on("change", function () {
var StudentUWLID = $(this).val();
$(this).attr('id', StudentUWLID);
$.ajax({
url: '@Url.Action("GetStudentRecordByID", "StudentProfile")',
type: "POST",
dataType: "JSON",
data: { _GivenStudentUWLID: StudentUWLID },
cache: false
}).done(function (data, textStatus, jqXHR) {
if (data.RecordStatus == "NotAvailable")
{
alert("error");
}
else if(data.RecordStatus=="recordFound")
{
// alert(data.Response);
var paraedData = JSON.parse(data.Response);
AdditionalTenentList.push(StudentUWLID);
....my rest of code
</script>