how to give value to model from radio button html asp with enums if checked code example
Example 1: how to give value to model from radio button html asp with enums if checked
public class TestModel
{
[Required(ErrorMessage = "select one item")]
public Airlines Airline { get; set; }
}
Example 2: 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 3: 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())
}