Set and Get the default value of checkbox in ASP.NET mvc -


i using checkbox in asp.net mvc project,

i can set check box default unchecked.

age:  <input class="associationcheckbox" type="checkbox" name="age" />

when post form (for has checkbox), checkbox not showing in formcollection (here expected name , value age, ‘false’).

using below code,i reading velues.

 [httppost]     public actionresult index(formcollection formcollection)     {         foreach (var key in formcollection.keys)         {             var value = formcollection[key.tostring()];         }           return redirecttoaction("corticonindex", "test");     } 

if check check box @ run time, submit form. can name , value.

how default values(false)if don’t check checkbox?

i tried setting value property using model property same issue coming.

model class:

public bool checkboxvalue { get; set; }  this.checkboxvalue=false 

age: <input class="associationcheckbox" type="checkbox" name="age" value=@model.checkboxvalue />

can suggest me how set , default value.

i had @ below post stack overflow didn't info requirement.

how set checkbox default checked in asp.net mvc

http://www.tutorialsteacher.com/mvc/htmlhelper-checkbox-checkboxfor

thanks, balu

you can this:

age: <input class="associationcheckbox" type="checkbox" name="age" @(model.checkboxvalue ? "checked" : "") value=@model.checkboxvalue /> 

but use htmlhelper methods if using razor


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -