0

I am creating a custom LabelFor. Inside it want to get the DataAnnotations properties linked to attribute mainly DataAnnotations created by me and I'm not getting. Example: Obrigatorio

I need to get the values of DataAnnotations for the labelFor leave the fields in bold when required. And depending on the validation, leave customized with styles.

My Class

public class GrupoRisco : IEntidadeBase
{
    [Key]
    public int GrupoRiscoID { get; set; }
    [Obrigatorio]
    [Display(Name="Descrição")]
    public string Descricao { get; set; }
}

My Custom Atribute

public class Obrigatorio : RequiredAttribute
{
    public Obrigatorio()
    {
        ErrorMessage = "* Obrigatório";
    }
}

The attribute above is simple, but will create complex attributes.

Tiedt Tech
  • 719
  • 15
  • 46
  • You might want to approach localisation from a different perspective: http://blog.gauffin.org/2010/11/simplified-localization-for-dataannotations/ – trailmax Jul 11 '16 at 13:20
  • Also this can be useful: http://stackoverflow.com/a/12810022/809357 – trailmax Jul 11 '16 at 13:21
  • Validations are on the TextBoxFor or EditorFor, not LabelFor. – Stephen Zeng Jul 11 '16 at 13:42
  • @StephenZeng I can not get the property to leave the label in bold when it is required? – Tiedt Tech Jul 11 '16 at 14:31
  • if that's the only requirement and it doesn't involve validation then that should be fairly straightforward. You don't even need to derive from required attribute. Just check if the property is marked as required. – Stephen Zeng Jul 11 '16 at 16:27

0 Answers0