I would like to be able to save several options of an enum (day of the week) something like 1.3.5 (Monday, Wednesday, Friday)
As the modeling described here.
I created a model
public class Horario
{
[Key]
public int ModalidadeProfessorSalaHorarioId { get; set; }
[DataType(DataType.Text)]
public DiaDaSemana DiaDaSemana { get; set; }
}
This day of the week is an enum
[Flags]
public enum DiaDaSemana
{
Domingo=0,
Segunda=1,
Terça=2,
Quarta=3,
Quinta=4,
Sexta=5,
Sábado=6
}
However when giving the migrations it creates as int
In the view the Insert I'm doing
@Html.EnumDropDownListFor(model => model.DiaDaSemana, new { @class = "form-control", multiple = "true" })
I'm thinking of creating the field as a string, creating a viewmodel to send the field as a string and the enum, and then in the controller do the union, I do not know if this is a gambiarra, but I think it would work.
Note: The [flag]
field of the enum together with @Html.EnumDropDownListFor
does not run, I need to disable the flag
O tipo de retorno 'Enums.DiaDaSemana' não tem suporte. O tipo não deve ter um atributo 'Flags'. Nome do parâmetro: expression