Questions tagged [displayattribute]

DisplayAttribute is a type of .NET Attribute that can be applied to types and classes to provide localized strings or formats

23 questions
234
votes
22 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,175
  • 4
  • 20
  • 31
137
votes
4 answers

displayname attribute vs display attribute

What is difference between DisplayName attribute and Display attribute in ASP.NET MVC?
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]…
13
votes
5 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…
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,228
  • 14
  • 42
  • 61
10
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
  • 20,983
  • 7
  • 64
  • 95
7
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,468
  • 14
  • 57
  • 108
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,126
  • 3
  • 27
  • 31
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 { …
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
  • 3,673
  • 2
  • 26
  • 36
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
  • 10,362
  • 17
  • 70
  • 150
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
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,606
  • 1
  • 10
  • 23
1
vote
3 answers

Display attribute in MVC doesnt display cyrillic in the HTML

I try to render cyrillic word "име" instead of the name of the column(FirstName) in the table from the DataBase but instead i receive some strange symbols "Èìå". I have a in my webconfig and also I've checked…
Georgi93
  • 27
  • 1
  • 7
1
vote
1 answer

Can't get value from resources file using reflection

I have two .resx files for localization - Global.en.resx and Global.resx(ru). Trying to get the value by name using ResourceManager I face a problem: the value displays only on Russian. ResourceManager rm = new ResourceManager(resourceType.FullName,…
1
2