user1765862
user1765862

Reputation: 14145

Two boolean properties in one radio choice

I have two properties

public bool IsSelOne {get; set;}
public bool IsSelTwo {get; set;}

currently there are inside view represented trough checkbox. How can without changing properties represent those choices trough radio button (IsSelOne, IsSelTwo)

Upvotes: 1

Views: 56

Answers (1)

Perfect28
Perfect28

Reputation: 11317

The best way to use a RadioButton is to map it with an enum. Anyway, you can use this kind of trick which needs an additional property :

public bool IsSelOne {get; set;}
public bool IsSelTwo {get; set;}

public bool Selection { 
   get { 
       return IsSelOne ; 
   } 
   set {
       IsSelOne = value;  
       IsSelTwo = !value ; 
   } 
}

Then in your view :

@Html.RadioButtonFor(m => m.Selection, true) ; // Radio for IsSelOne true 
@Html.RadioButtonFor(m => m.Selection, false) ; // Radio for  IsSelTwo true 

Upvotes: 1

Related Questions