DisplayAttribute is a type of .NET Attribute that can be applied to types and classes to provide localized strings or formats
Questions tagged [displayattribute]
26 questions
285
votes
26 answers
How to get the Display Name Attribute of an Enum member via MVC Razor code?
I've got a property in my model called Promotion that its type is a flag enum called UserPromotion. Members of my enum have display attributes set as follows:
[Flags]
public enum UserPromotion
{
None = 0x0,
[Display(Name = "Send Job Offers…

Pejman
- 3,784
- 4
- 24
- 33
153
votes
4 answers
displayname attribute vs display attribute
What is difference between DisplayName attribute and Display attribute in ASP.NET MVC?

Ghooti Farangi
- 19,926
- 15
- 46
- 61
17
votes
6 answers
ASP.NET Core DisplayAttribute Localization
According to the documentation:
The runtime doesn’t look up localized strings for non-validation attributes. In the code above, “Email” (from [Display(Name = "Email")]) will not be localized.
I'm looking for a way to localize text in…

David
- 460
- 2
- 7
- 17
14
votes
3 answers
ASP.NET MVC 3 localization with DisplayAttribute and custom resource provider
I use a custom resource provider to get resource strings from a database. This works fine with ASP.NET where I can define the resource type as a string. The metadata attributes for model properties in MVC 3 (like [Range], [Display], [Required]…

slfan
- 8,950
- 115
- 65
- 78
11
votes
3 answers
About Enum and DataAnnotation
I have this Enum (Notebook.cs):
public enum Notebook : byte
{
[Display(Name = "Notebook HP")]
NotebookHP,
[Display(Name = "Notebook Dell")]
NotebookDell
}
Also this property in my class (TIDepartment.cs):
public Notebook Notebook {…

developer033
- 24,267
- 8
- 82
- 108
10
votes
2 answers
what is the advantage of DisplayName attribute than Display attribute?
The result of [DisplayName("foo")] and [Display(Name="foo")] for @Html.LabelFor(x => x.MyProperty) is same. both generate . what is the advantage of DisplayName?

Ghooti Farangi
- 19,926
- 15
- 46
- 61
8
votes
2 answers
DisplayAttribute name with a variable, Dynamic DisplayName
Wondering if this is possible or something with this effect.
public class MyModel
{
public string Name { get; set; }
[Display(Name = String.Format("This is [0]'s phone number", Name)]
public string PhoneNumber { get; set; }
}
I'm…

Ingó Vals
- 4,788
- 14
- 65
- 113
5
votes
1 answer
Access keys in ASP.NET MVC
I'm intending to extend the Display DataAnnotation attribute to hold a value for the AccessKey for an input field so I can use it in my own LabelFor<> and TextBoxFor<> HtmlHelper extensions, something like this:
[Display(Name = "User name",…

Oundless
- 5,425
- 4
- 31
- 33
4
votes
1 answer
How to customize Display and Required attributes at run-time in MVC
I would like to have a model with a dynamic label in the razor view that gets set at runtime but is based on a string from a resource file using string formatting.
Lets say I have a simple model with a single property
public class Simple
{
…

Paul Marsden
- 151
- 11
4
votes
1 answer
ASP MVC non-breaking-space in Display attribute with DisplayNameFor
I have a model with a Property "Price" which has the DisplayAttribute
[Display(Name = "Price (in €)")]
Now i want to display this in a table header using
@Html.DisplayNameFor(model => model.Price)
But when the column is very small, the Text might…

wertzui
- 5,148
- 3
- 31
- 51
2
votes
3 answers
Create a custom DisplayAttribute for enums?
I've got an enum class...
public enum LeadStatus : byte
{
[Display(Name = "Created")] Created = 1,
[Display(Name = "Assigned")] Assigned = 2,
....
}
Name of course is out-of-the-box. From MetaData...
namespace…

Casey Crookston
- 13,016
- 24
- 107
- 193
2
votes
1 answer
The namespace name 'Display' and 'DisplayAttribute' could not be found
When trying to compile my .Dll I have managed to get all my references and errors figured out except for these two(which i have multiple of).
"The type or namespace name 'Display' could not be found(are you missing a using directive or an assembly…

Justin Reid
- 21
- 1
- 3
2
votes
6 answers
Is it better to not render HTML at all, or add display:none?
As far as I understand, not rendering the HTML for an element at all, or adding display:none, seem to have exactly the same behavior: both make the element disappear and not interact with the HTML.
I am trying to disable and hide a checkbox. So the…

djechlin
- 59,258
- 35
- 162
- 290
1
vote
1 answer
Is it possible to format Display attribute's Name property value of MVC Model class?
What I mean is, e.g.
[DataType(DataType.Text)]
[Display(Name = "Corporation / Entreprise")]
public string Corporation { get; set; }
Would it be possible to apply a line break after the '/' in the Name of the Display attribute?
So when the View page…

Xiao Han
- 1,004
- 7
- 16
- 33
1
vote
1 answer
DisplayAttribute not work in Dotnet Core buddy class
I've been trying to attach a DisplayAttribute to a field in my buddy class in Dotnet Core, but it not appears in my View. for example in View display "Title" instead "عنوان".
The two classes are linked via ModelMetadataType.
where is wrong?
orginal…

Morteza Jangjoo
- 1,780
- 2
- 13
- 25