c# - Proper way to create a radiobuttonlist without having any of the radiobuttons checked by default -


the nullable identifier makes radiobuttonlist not check of radiobuttons default on first page load. proper way handle scenario? or best practice?

model:

[required] public someenum? choices { get; set; }  public enum someenum {     optionone,     optiontwo } 

view:

<div>     @html.validationmessagefor(x => x.choices)     @html.radiobuttonfor(x => x.choices, someenum.optionone)     @html.radiobuttonfor(x => x.choices, someenum.optiontwo) </div> 

rendered html:

<div>     <input name="choices" id="choices" type="radio" data-val-required="the choices field required." data-val="true" value="optionone"></input>     <input name="choices" id="choices" type="radio" value="optiontwo"></input> </div> 

yes, using best model represent radio list no default value. right purpose null.

an advantage of approach [required] attribute makes easy validate option has been selected.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -