My model contains an enumeration that I am trying to associate with a list of radio buttons so that only one value can be selected when submitting the form.
public enum Options
{
[Display(Name="Option A")
OptionA,
[Display(Name="Option B")
OptionB
}
public class MyModel
{
public Options SelectedOption {get; set;}
public string TextA{get; set;}
public string TextB{get; set;}
}
In MVC 5, I would provide a switch input for each enumeration value, and the user could only select one. Thus, the code in the view for each switch is likely to look like this:
@Html.RadioButtonFor(m => m.SelectedOption, Options.OptionA)
The problem with MVC6 is that the helper input tag does not support the enum property out of the box. Therefore, if I try to add <input asp-for="SelectedOption"/>, all I get is a text box.
, : MVC6 ( ) ? , - ?
, , , enum [Display]. , TextA TextB , , . , ( ):
<div>
<div>
<input id="OptionA" type="radio" name="SelectedOption"/>
<label for="OptionA">Option A</label>
</div>
<div>
<label for="TextA">Text A</label>
<input type="text" id="TextA" name="TextA">
</div>
<div>
<div>
<div>
<input id="OptionB" type="radio" name="SelectedOption"/>
<label for="OptionB">Option B</label>
</div>
<div>
<label for="TextB">Text A</label>
<input type="text" id="TextB" name="TextB">
</div>
<div>