Razor ページ (ASP.NET Core) で列挙型の値を反復処理しているときに、列挙型の表示名を表示するにはどうすればよいですか?
かみそりのページ:
<label asp-for="Survey.ToldNotToTakeHormones"></label><br />
@foreach (var answer in Enum.GetValues(typeof(AnswerYND)))
{
<div class="custom-control custom-radio custom-control-inline ">
<label><input type="radio" asp-for="Survey.ToldNotToTakeHormones" value="@answer" />@answer</label>
</div>
}
かみそりページの背後にあるコード:
public class EditModel : PageModel
{
[BindProperty]
public Survey Survey { get; set; }
調査クラス:
public class Survey
{
[Display(Name = "Have you ever been told by a medical professional not to take hormones?")]
public AnswerYND? ToldNotToTakeHormones { get; set; }
回答YND:
public enum AnswerYND
{
Yes,
No,
[Display(Name="Don't Know")]
DontKnow
}