2
Follows the code:
Model:
public bool teste{ get; set; }
View:
<div class="checkbox">
@Html.CheckBoxFor(model => model.teste)
</div>
HTML result:
<div class="checkbox">
<div class="lcs_wrap"><input checked="checked" data-val="true" id="teste" name="teste" type="checkbox" value="true">
<div class="lcs_switch lcs_checkbox_switch lcs_on">
<div class="lcs_cursor"></div>
<div class="lcs_label lcs_label_on"><span class="glyphicon glyphicon-ok"></span></div>
<div class="lcs_label lcs_label_off"><span class="glyphicon glyphicon-remove"></span></div>
</div>
</div>
<input name="teste" type="hidden" value="false">
</div>
Script:
I’ve tried several ways:
Attempt 1
var teste= $('#teste').prop('checked');
Attempt 2
var teste= $("#teste").is(":checked");
Attempt 3
$('body').delegate('#teste', function() {
var teste = ($(this).is(':checked')) ? 'checked' : 'unchecked';
});
On the line : <div class="lcs_switch lcs_checkbox_switch lcs_on">
= true
When false <div class="lcs_switch lcs_checkbox_switch lcs_off">
= false
Some solution ?
I think the problem is in the #test input being
type="hidden"
, no propertychecked
for this type of input– Miguel