Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:01:57+00:00 2026-06-12T07:01:57+00:00

I am starting out with MVC 4 (Razor view engine). (I believe this may

  • 0

I am starting out with MVC 4 (Razor view engine). (I believe this may apply to MVC 3 and earlier as well.) I am wondering if there is any benefit to using the DisplayAttribute data annotation within a view versus just writing a string directly in the HTML. For example, if I had the following model:

public class Thing
{
    public string WildAndCrazyProperty { get; set; }
}

…would there be any benefit in annotating the property as:

    [Display(Name = "Wild and Crazy")]
    public string WildAndCrazyProperty { get; set; }

…and having my markup be:

<html>
    <body>
        <div>@Html.DisplayNameFor(modelItem => modelItem.WildAndCrazyProperty)</div>
        <div>@Html.DisplayFor(modelItem => modelItem.WildAndCrazyProperty)</div>
    </body>
</html>

…versus not having the annotation, and doing:

<html>
    <body>
        <div>Wild and Crazy</div>
        <div>@Html.DisplayFor(modelItem => modelItem.WildAndCrazyProperty)</div>
    </body>
</html>

The reason I haven’t mentioned Html.LabelFor in this case is because the property’s data is being displayed as static (i.e. non-editable) text on the page. The data will never be editable on this page, so there is no need for me to use Html.TextBoxFor within the second <div> and subsequently use the Html.LabelFor to properly associate a label with that text box.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:01:58+00:00Added an answer on June 12, 2026 at 7:01 am

    If two different views are sharing the same model (for instance, maybe one is for mobile output and one is regular), it could be nice to have the string reside in a single place: as metadata on the ViewModel.

    Additionally, if you had an inherited version of the model that necessitated a different display, it could be useful. For instance:

    public class BaseViewModel
    {
        [Display(Name = "Basic Name")]
        public virtual string Name { get; set; }
    }
    
    public class OtherViewModel : BaseViewModel
    {
        [Display(Name = "Customized Inherited Name")]
        public override string Name { get; set; }
    }
    

    I’ll admit that that example is pretty contrived…

    Those are the best arguments in favor of using the attribute that I can come up with. My personal opinion is that, for the most part, that sort of thing is best left to the markup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to learn MVC 3 with the Razor view engine and
I'm starting out with MVC but not sure it's the best option. I need
Just starting out, this should be a simple one but I haven't been able
I am just starting out on functions in PostgreSQL, and this is probably pretty
I'm starting out with backbone and I'm trying to create a simple view that
I'm just starting out in ASP.NET MVC (and web applications in general, as I've
I Just starting out w/ ASP.NET MVC 3 and I am trying to render
i'm just starting out with asp.net mvc. It's a long way before you can
I am just starting out with the Entity Framework 4.0 and ASP.NET MVC 2
I'm just starting out in MVC world, and I've used a standard MVC template

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.