c# - Using the name data annotation vs hard coding in view -
i have following in entityframework domain models:
[required] [display(name = "first name")] public string firstname { get; set; } [required] [display(name = "last name")] public string lastname { get; set; }
and in view following:
@html.labelfor(model => model.firstname)
but wondering, why preferred specify "display name" in model instead of writing label manually in view page?
i can see causing more problems, if in 6 months time comes me , says "we don't want first name anymore, want "your first name" either have revert hard coding in view or recompile model project change take effect..
is there benefits not aware of using data annotations?
the benefit of displayattribute
localization code below.
[required] [display(name = "first name", resourcetype = typeof(yourresources)))] public string firstname { get; set; }
asp.net mvc 3 localization displayattribute , custom resource provider has answers localization , different way achieve it.
Comments
Post a Comment