c# - Razor checkbox not binding to Model -


i'm asp.net mvc newbie. have checkbox in form

@html.checkbox("don't show number", model.isphonepublic) 

but whether check box or not model.isphonepublic false while submitting form. pointers

you using helper wrong, see definition here :

so this:

@html.label("don't show number")  @html.checkbox("isphonepublic", model.isphonepublic) 

or

@html.label("don't show number")  @html.checkboxfor(m => m.isphonepublic) 

or third , clean solution:

@html.labelfor(m => m.isphonepublic)  @html.checkboxfor(m => m.isphonepublic) 

and in model definition:

[displayname("don't show number")] public bool isphonepublic { get; set; } 

Comments

Popular posts from this blog

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

clojure - 'get' replacement that throws exception on not found? -