2
In the model I have:
[Display(Name = "Exemplo 1")]
[Range(typeof(bool), "true", "true", ErrorMessage = "Erro, marcar como true")]
public bool Exemplo1 { get; set; }
[Display(Name = "Exemplo 2")]
public bool Exemplo2 { get; set; }
[Display(Name = "Exemplo 3")]
public bool Exemplo3 { get; set; }
In the view I have :
@Html.CheckBoxFor(model => model.Exemplo1, new { id = "toggle1", data_on = "Sim", data_off = "Não", data_toggle = "toggle", data_class = "fast", data_size = "mini", data_onstyle = "success", data_offstyle = "danger" })
@Html.ValidationMessageFor(model => model.Exemplo1, "", new { @class = "text-danger" })
@Html.CheckBoxFor(model => model.Exemplo2, new { id = "toggle2", data_on = "Sim", data_off = "Não", data_toggle = "toggle", data_class = "fast", data_size = "mini", data_onstyle = "success", data_offstyle = "danger" })
@Html.CheckBoxFor(model => model.Exemplo3, new { id = "toggle3", data_on = "Sim", data_off = "Não", data_toggle = "toggle", data_class = "fast", data_size = "mini", data_onstyle = "success", data_offstyle = "danger" })
I have a "Create" post button. By clicking "Create" button, show red warning when the 3 checkbox buttons is 3 false. Must be at least 1 true to process post.
How to do this using Data Annotations ?
Ivalidatableobject Interface option worked. It works like [Required] instead of using [Range(typeof(bool), "true", "true", Errormessage = "Error, mark as true")] ?
– Matheus Miranda
@Matheusmiranda With the interface you can add the validation you want. Check if it is null, if it is greater than such a date, if it needs another value and what your mind desires. Remembering that there is no need to use this if the Data Annotations meet.
– Randrade