3
I wish I could save several options of an Enum (day of the week) something like 1,3,5 (Monday, Wednesday, Friday)
I created a model
public class Horario
{
[Key]
public int ModalidadeProfessorSalaHorarioId { get; set; }
[DataType(DataType.Text)]
public DiaDaSemana DiaDaSemana { get; set; }
}
That 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
}
But when giving Migrations it creates as int
In the view I’m doing Insert
@Html.EnumDropDownListFor(model => model.DiaDaSemana, new { @class = "form-control", multiple = "true" })
I’m thinking about creating the field as a string, creating a viewmodel sending the field as string and Enum, and then in the controller doing the union, I don’t know if this is a scam, but I think it would work.
OBS: The field [flag]
of Enum together with the @Html.EnumDropDownListFor
do not turn, need to disable 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
What is the need to keep in the bank?
– Jéf Bueno
I need to save the days of the week in the bank!
– Dorathoto
That I understood, I’m asking the reason.
– Jéf Bueno
I put the modeling link
– Dorathoto
An Enum is just a Nickname for a mapping constant or id. Internally it is converted to the appropriate type. Treat as such, take int from the bank and cast. Be careful with this: https://msdn.microsoft.com/pt-br/library/sbbt4032.aspx
– Intruso