Good morning
I have a model with some options as enums that i want to appear in the form automaticly. How ?
"CampaignType" and "CampaignStatus"
I tryed to add:
asp-items="Html.GetEnumSelectList()"
But VS2022 didn't like it.
My Model:
using Microsoft.AspNetCore.Identity;
using System.ComponentModel.DataAnnotations;
namespace HyperWeb_V3.Models
{
public class MarketingCampaign
{
.
.
.
[Required(ErrorMessage = "Please select the type of campaign.")]
public CampaignType Type { get; set; }
[Required(ErrorMessage = "Please select the status of the campaign.")]
public CampaignStatus Status { get; set; }
.
.
.
}
public enum CampaignType
{
Advertisement,
Email,
Webinar,
Conference,
Other
}
public enum CampaignStatus
{
Planned,
InProgress,
Completed
}
}
My Form:
.
.
.
Best regards
Rui Ruivo
Mohamed Azarudeen ZPosted Jul 2, 2023, 5:17 PM
Hi Rui
To resolve this issue, you can modify your form code as follows:
@usingdirective at the top of the .cshtml file:Modify the
tags for theTypeandStatusproperties to use the appropriateEnum.GetValuesmethod to generate the options for the dropdown lists: