我试图显示未从数据库值中选中的复选框,但我没有找到任何解决方案。请帮忙。
下面是我尝试过的代码
<table class="table table-bordered table-striped" id="tblBrand">
<thead>
<tr>
<th>Brand Name</th>
<th>ISActive</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: '@Url.Action("GetBrand", "Product")',
dataType: "json",
async: false,
contentType: "application/json; charset=utf-8",
success: function (result) {
var data = result.brandList;
BindBrand(data);
}
});
});
function BindBrand(msg) {
var properties = {
bProcessing: true,
bDestroy: true,
bSort: true,
data: msg,
aoColumns: [
{ mData: 'GlobalCodeName' },
{
mData: "",
bSortable: false,
mRender: function (cellvalue, options, rowObject) {
if (rowObject.IsActive === true) {
$('input:checked');
}
debugger;
return '<input id="checkid' + rowObject.GlobalCodeID + '" class="mycheckbox" type="checkbox" onchange="Updatecheckboxvalue(' + rowObject.GlobalCodeID + ');"></input> ';
}
}
]
};
var table = $('#tblBrand').DataTable(properties);
}
</script>
上面是视图中的代码
下面是控制器中的代码
[HttpGet]
public JsonResult GetBrand()
{
var finalResult = Common.GetProductBrand("1001");
var JSONString = JsonConvert.SerializeObject(finalResult);
var brandList = JsonConvert.DeserializeObject<IEnumerable<GlobalCodes>>(JSONString);
//return Json(brandList, JsonRequestBehavior.AllowGet);
return Json(new { brandList }, JsonRequestBehavior.AllowGet);
}
我希望在我的视图中应该检查复选框,如果我数据库中的IsActive列为true,并且如果为false,则复选框的值应该为false
答案 0 :(得分:0)
让我们这样尝试:
mRender: function (cellvalue, options, rowObject) {
debugger;
return '<input id="checkid' + rowObject.GlobalCodeID + '" class="mycheckbox" type="checkbox" onchange="Updatecheckboxvalue(' + rowObject.GlobalCodeID + ');" ' + (rowObject.IsActive === true)?'checked':'' + '>';
}