mvc core radio button list enum model binding code example
Example 1: how to fill model enum with bradio button asp razor
@{var numList = Enum.GetValues(typeof(Models.numbers));}
@foreach (object radiotext in numList)
{
@Html.RadioButton("radioname", radiotext.ToString())@radiotext.ToString()
}
Example 2: how to fill model enum with bradio button asp razor
namespace Models
{
public enum numbers
{
one = 1,
two = 2,
three = 3
}
}
Example 3: how to give value to model from radio button html asp with enums if checked
@model MvcTest.Models.Airlines
@foreach (var value in Enum.GetValues(typeof(MvcTest.Models.Airlines)))
{
@Html.RadioButtonFor(m => m, value)
@Html.Label(value.ToString())
}
Example 4: how to give value to model from radio button html asp with enums if checked
@model Enum
@foreach (var value in Enum.GetValues(Model.GetType()))
{
@Html.RadioButtonFor(m => m, value)
@Html.Label(value.ToString())
}