asp.net - set unchecked value of checkbox -


is there way of setting default unchecked value of checkbox? not using databound control. passing data form , pass false opposed null when unchecked.

yes, using default htmlhelpers achieve you

<%: html.checkbox("mycheckbox") %> 

or razor

@html.checkbox("mycheckbox") 

the checkbox() method render input type="hidden" field along side input type="checkbox" submit value false when checkbox unchecked.

<input id="mycheckbox" name="mycheckbox" type="checkbox" value="true" /> <input name="mycheckbox" type="hidden" value="false" /> 

if want submit value other false should render checkbox , hidden field setting value of hidden field default value. note must have same name attribute.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -