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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -