displayattribute

displayname attribute vs display attribute

独自空忆成欢 提交于 2020-01-08 15:40:30
问题 What is difference between DisplayName attribute and Display attribute in ASP.NET MVC? 回答1: They both give you the same results but the key difference I see is that you cannot specify a ResourceType in DisplayName attribute. For an example in MVC 2, you had to subclass the DisplayName attribute to provide resource via localization. Display attribute (new in MVC3 and .NET4) supports ResourceType overload as an "out of the box" property. 回答2: DisplayName sets the DisplayName in the model

displayname attribute vs display attribute

青春壹個敷衍的年華 提交于 2020-01-08 15:39:57
问题 What is difference between DisplayName attribute and Display attribute in ASP.NET MVC? 回答1: They both give you the same results but the key difference I see is that you cannot specify a ResourceType in DisplayName attribute. For an example in MVC 2, you had to subclass the DisplayName attribute to provide resource via localization. Display attribute (new in MVC3 and .NET4) supports ResourceType overload as an "out of the box" property. 回答2: DisplayName sets the DisplayName in the model

ASP.NET Core DisplayAttribute Localization

被刻印的时光 ゝ 提交于 2019-12-19 16:28:26
问题 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 DisplayAttribute. Any suggestions to do it in a proper way(s)? 回答1: You can set the ResourceType on the DisplayAttribute which can be used to localize your text. Add a resource .resx file to your project e.g. MyResources.resx , and add a resource for your field:

About Enum and DataAnnotation

旧街凉风 提交于 2019-12-10 03:53:56
问题 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 { get; set; } It's working perfectly, I just have one "problem": I created an EnumDDLFor and it's showing the name I setted in DisplayAttribute, with spaces, but the object doesn't receive that name in DisplayAttribute, receives the Enum name (what is correct), so my

About Enum and DataAnnotation

倾然丶 夕夏残阳落幕 提交于 2019-12-05 04:30:35
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 { get; set; } It's working perfectly, I just have one "problem": I created an EnumDDLFor and it's showing the name I setted in DisplayAttribute, with spaces, but the object doesn't receive that name in DisplayAttribute, receives the Enum name (what is correct), so my question is: Is there a way to receive the name with spaces which one I configured in DisplayAttribute

ASP.NET Core DisplayAttribute Localization

旧城冷巷雨未停 提交于 2019-12-01 16:59:30
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 DisplayAttribute. Any suggestions to do it in a proper way(s)? You can set the ResourceType on the DisplayAttribute which can be used to localize your text. Add a resource .resx file to your project e.g. MyResources.resx , and add a resource for your field: Then reference the name of the field and the MyResources type in your DisplayAttribute [Display(Name =

DisplayAttribute name with a variable, Dynamic DisplayName

我是研究僧i 提交于 2019-12-01 16:40:00
问题 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 talking about a DisplayName with a variable in it, non static and possibly based on the models other properties. Is this possible in any way? 回答1: This isn't possible because the arguments specified for parameters of attributes must be constant values (instinctively,

ASP.NET MVC 3 localization with DisplayAttribute and custom resource provider

天大地大妈咪最大 提交于 2019-11-28 10:54:06
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] require the type of a Resource as a parameter, where the ResourceType is the type of the generated code-behind class of a .resx file. [Display(Name = "Phone", ResourceType = typeof(MyResources))] public string Phone { get; set; } Because I don't have .resx files, such a class does not exist. How can I use the model attributes with a custom resource

ASP.NET MVC 3 localization with DisplayAttribute and custom resource provider

☆樱花仙子☆ 提交于 2019-11-27 03:53:25
问题 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] require the type of a Resource as a parameter, where the ResourceType is the type of the generated code-behind class of a .resx file. [Display(Name = "Phone", ResourceType = typeof(MyResources))] public string Phone { get; set; } Because I don't have

displayname attribute vs display attribute

旧城冷巷雨未停 提交于 2019-11-26 19:40:20
What is difference between DisplayName attribute and Display attribute in ASP.NET MVC? Spock They both give you the same results but the key difference I see is that you cannot specify a ResourceType in DisplayName attribute. For an example in MVC 2, you had to subclass the DisplayName attribute to provide resource via localization. Display attribute (new in MVC3 and .NET4) supports ResourceType overload as an "out of the box" property. Darin Dimitrov DisplayName sets the DisplayName in the model metadata. For example: [DisplayName("foo")] public string MyProperty { get; set; } and if you use