I work on asp.net mvc web app I face issue i can't make check box no selection if value of speakstuff is null so i will not make default value false i need speak stuff when display for first time of user to display as null so how to change my code to accept if speakstuff is null then no checked by true or false my code as below :
$(document).ready(function () {
$('.speak-stuff-checkbox').on('change', function () {
$('.speak-stuff-checkbox').not(this).prop('checked', false);
var selectedValue = $(this).val();
$('#SpeakStuff').val(selectedValue);
});
});
@Html.Label("Did You Meet/Speak to Staff", htmlAttributes: new { @class = "control-label col-md-5" })
Yes
No
public class ResignationRequester
{
public int RequestNo { get; set; }
public bool SpeakStuff { get; set; }
}
when assign value to speakstuff it made as below :
obj.SpeakStuff = F6000059["REEV01"].ToString().ToUpper() == "Y" ? true : false;
Sachin SinghPosted Jan 14, 2024, 3:43 PM
Jithu ThomasPosted Jan 14, 2024, 1:51 PM
Also you need to modify the class like this: -
public class ResignationRequester
{ public int RequestNo { get; set; }
public bool? SpeakStuff { get; set; }
}
Tahir AnsariPosted Jan 14, 2024, 1:41 PM
You can do this by checking whether
Model.SpeakStuffisnullbefore applying thecheckedattribute.This way, if
Model.SpeakStuffisnull, neither checkbox will have thecheckedattribute, and they will both appear unchecked. IfModel.SpeakStuffistrue, the "Yes" checkbox will be checked, and if it'sfalse, the No checkbox will be checked.