Hello @Ahmed Salah Abed Elaziz
In your current code, SpeakStuff
is a non-nullable Boolean, which means it can only be true
or false
. If you want it to be able to represent a third state (i.e., null
), you should change the type of SpeakStuff
to bool?
(nullable boolean) in your ResignationRequester
class.
Here’s how you can modify your class:
public class ResignationRequester
{
public int RequestNo { get; set; }
public bool? SpeakStuff { get; set; } // Nullable boolean
}
And in your view, you can handle the nullable boolean like this:
<input type="checkbox" id="SpeakStuff" name="SpeakStuff" value="true" class="speak-stuff-checkbox" @(Model.SpeakStuff == true ? "checked" : "") disabled />
Yes
<input type="checkbox" id="SpeakStuff" name="SpeakStuff" value="false" class="speak-stuff-checkbox" @(Model.SpeakStuff == false ? "checked" : "") disabled />
No
In this code, if SpeakStuff
is null
, neither of the checkboxes will be checked. Please note that you might need to adjust your JavaScript and assignment code accordingly to handle the nullable boolean. Also, remember that the IDs of your HTML elements should be unique. In your code, both checkboxes have the same ID SpeakStuff
, which might cause issues. You might want to consider giving them different IDs.
I hope this helps! If this solved your query, please tag this answer as accepted, as it helps the further community readers who may be looking for similar answers.