mvc bind/post boolean to radiobutton

前端 未结 4 970
有刺的猬
有刺的猬 2021-02-07 20:29

I have a column in my Model with a NULLABLE boolean value. Now on my View (for editing), I would like to bind that to two radiobuttons: Yes & No. If the value is null, then

4条回答
  •  不知归路
    2021-02-07 21:10

    Once you have selected a radio button, there's really no way to unselect it (as a user). I'd suggest that if you really need a three-valued result, that you have three radio buttons -- Yes, No, Don't care.

    <%= Html.LabelFor( m => m.Foo ) %>
    <%= Html.RadioButtonFor( m => m.Foo, "true" ) %> Yes
    <%= Html.RadioButtonFor( m => m.Foo, "false" ) %> No
    <%= Html.RadioButtonFor( m => m.Foo, string.Empty ) %> Don't Care
    <%= Html.ValidationMessageFor( m => m.Foo ) %>
    

提交回复
热议问题