I have a checkbox in a partial view
<div>Full time: @Html.CheckBoxFor(model => model.FullTime, new { htmlAttributes = new { id = "txtIsFullTime" } })</div>
in the same partial view I have this Ajax code:
<script>
var urlAction = "@Url.Content("~/Treeview/_NewEmpThird")";
function AjaxGoodRedirect(urlAction) {
console.log(urlAction);
$.ajax({
type: "POST",
url: urlAction,
data: JSON.stringify({ FullTime: $("#txtIsFullTime").val() }), //data: JSON.stringify({ ID: 1, Forename: "FName", Surname: "SName" }),
datatype: "JSON",
contentType: "application/json; charset=utf-8",
success: function (returndata) {
if (returndata.ok)
$("#detailView").load(returndata.newurl);
else
window.alert(returndata.message);
}
}
);
}
But it is passing back a False value every time.
I used the same method for an @Html.EditorFor and had no problems - can anyone help point out where i have gone wrong?
thanks :)
edit
Think the issue was with the new html attributes = new.. removed that (and corrected the typo)
div>Full time: @Html.CheckBoxFor(model => model.FullTime, new { id = "txtFullTime" })
then used
data: JSON.stringify({ ID: $("#txtFullTime").is(':checked') ? 1 : 0 })
and no returns 1 or 0.