MVC3 EditorTemplate for a nullable boolean using RadioButtons

前端 未结 6 1877
深忆病人
深忆病人 2020-12-05 10:55

I have a property on one of my objects that is a nullable boolean, I want my logic to have true represent Yes, false to be No and null to be N/A. Now because I am going to h

6条回答
  •  隐瞒了意图╮
    2020-12-05 11:19

    The problem is that you need to set the checked attribute because the Html.RadioButtonFor does not check a radio button based on a nullable bool (which appears to be a flaw).

    Also by putting the radio buttons inside of the label tag, you can select value by clicking the label.

    Shared/EditorTemplates/Boolean.cshtml

    @model bool?
    
    
    
    

提交回复
热议问题