How to do checkbox control in ASP.net Core -


//part of view     <div class="checkbox">         <label id="sendemail" class="" >             <input id="sendemailinput" type="checkbox" asp-for="companysetting.sendemail">send mail jobs.         </label>     </div>   //model     public partial class companysetting     {         public int companyid { get; set; }         public bool sendemail { get; set; }          public virtual companyusers company { get; set; }     } //controller     public actionresult accountsettingsave(companyaccountviewmodel model)     {         try         {             companysetting settingmodel = _companysettingservice.getbycompanyid(getid());             settingmodel.sendemail = model.companysetting.sendemail;             _companysettingservice.updatebill(settingmodel);             tempdatamessage("message", "hesap ayarları başarıyla güncellendi.");             return redirecttoaction("accountsettings");         }         catch         {             tempdatamessage("message", "hesap ayarları güncellenemedi.");             return redirecttoaction("accountsettings");         }      } 

checbox not affect model, default value. checkbox returns on. tried javascript + 1 input , works . dont want use javascirpt control

<div class="checkbox">     <input id="sendmail" type="text" asp-for="companysetting.sendemail" style="display: none" />     <label id="sendmaillabel"><input  type="checkbox">send mail jobs</label> </div>  if ($('#sendmail').val() == 'true') {     $('#sendmaillabel').addclass('checked'); } else {     $('#sendmaillabel').removeclass('checked'); } $('#sendmaillabel').on('change', function () {     if ($('#sendmaillabel').hasclass('checked')) {         $('#sendmail').val('true');     } else {         $('#sendmail').val('false');     } }); 

this code works. should use it?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -