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

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -