c# - Setting checkbox values in MVC4 -


in html code want create checkboxes readonly , value depends on data database. setting readonly property fine , binding checkbox model. value on model (that came database) integer, not boolean. i'm doing

@html.checkbox("myproperty", model.property == 2 ? true : false, new { @onclick = "return false" }) <label>some text label</label> 

so wondering if there way achieve without if statement

thank advice

know question old, perhaps worth mentioning perhaps more elegant way of doing creating property on model interpretation of .property value.

class model //the name of model {     //...     public int property { get; set; }     public bool myproperty {                     {             return this.property == 2;         }     } } 

and in view:

@html.checkbox("myproperty", model.myproperty, new { @onclick = "return false" }) <label>some text label</label> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -