I work on asp.net mvc 5 I face issue when property SpeakStuff null it display error on console of browser tell me property SpeakStuff null so How to prevent error on console when property SpeakStuff is null how to handle it .
How to avoid error null when submit .
wht i try as below
<a onclick="submit();" class="btn btn-primary" style="min-width: 100px;margin-top:5px; margin-left: 1300px;"><i class="glyphicon glyphicon-ok"></i> Approve </a> java script function for submit function submit() { console.log("check submit"); var ResignationRequester = new Object(); ResignationRequester.SpeakStuff = document.getElementById('SpeakStuff').checked; } csharp main model i will submit public class ResignationRequester { public bool SpeakStuff { get; set; } } controller action catched when update data and submit [ValidateAntiForgeryToken] public async Task<ActionResult> ApprovalIndex(ResignationRequester REQ) { } on asp.net mvc view sometimes session not detected or catch property Model.SpeakStuff so it display null @if (Session[BLL.Common.SessionKeys.RoleCode].ToString() == "LM" || Session[BLL.Common.SessionKeys.RoleCode].ToString() == "LDM" || Session[BLL.Common.SessionKeys.RoleCode].ToString() == "DM") { <h2 style="font-weight:bold;">Questions For Manager Before Approving:</h2> if (Model.DirectManagerStatus == "Approve") { <div> @Html.Label("Did You Meet/Speak to Staff", htmlAttributes: new { @class = "control-label col-md-5" }) <div class="col-md-7"> <input type="checkbox" id="SpeakStuff" name="SpeakStuff" value="true" class="speak-stuff-checkbox" @(Model.SpeakStuff ? "checked" : "") /> Yes <input type="checkbox" id="SpeakStuff" name="SpeakStuff" value="false" class="speak-stuff-checkbox" @(!Model.SpeakStuff ? "checked" : "") /> No </div> </div> $('.speak-stuff-checkbox').on('change', function () { $('.speak-stuff-checkbox').not(this).prop('checked', false); var selectedValue = $(this).val(); $('#SpeakStuff').val(selectedValue); });