1

What is the difference between the following three annotations:

[ScaffoldColumn(false)]
[Display(Name = "")]
[Display(AutoGenerateField=false)]

There are related SO questions here and there, but I believe none that cover all three. I've also seen an SO post that claims the AutoGenerateField=false accomplishes nothing. If so, then what is it for? As for the other two annotations -ScaffoldColumn(false) and Display(Name="") - are they equivalent?

Community
  • 1
  • 1
Brent Arias
  • 29,277
  • 40
  • 133
  • 234

2 Answers2

4
  1. ScaffoldColumn(false): Hides the display or editor field only when you use @Html.DisplayForModel() or @Html.EditorForModel (respectively), and only so long as you are using the default display and editor templates. If you override the built-in templates, you will need to add back in support for this attribute in your template.
  2. Display(Name=""): Affects the text displayed as the label for DisplayForModel, Label, LabelForModel, and EditorForModel. In this case, the display name is set to an empty string, so that literally will be output as the label. That will not prevent the label from being generated.
  3. Display(AutoGenerateField=false): Appears to be unrecognized by any of the default templates or helpers, as you suggested.

No, 1 and 2 are not the same.

moribvndvs
  • 42,191
  • 11
  • 135
  • 149
0

When marked with ScaffoldColumn(false)

public class Hate
{
    [ScaffoldColumn(false)]
    public string What { get; set; }

    public string Why { get; set; }
}

@model StrippingHtml.Models.Hate
@{
  ViewBag.Title = "What & Why You Hate";
}
<h2>
  What & Why You Hate</h2>
@using (Html.BeginForm("Save", "Hate"))
{
  <div>
    @Html.EditorForModel()
  </div>
}

enter image description here

When marked with Display(Name="")

public class Hate
{
    [Display(Name="")]
    public string What { get; set; }

    public string Why { get; set; }
}

enter image description here

VJAI
  • 32,167
  • 23
  • 102
  • 164