1

I am learning ASP.NET Core, the ways to display the Model properties on a View...

So, I discovered the DisplayAttribute.ShortName property that

Gets or sets a value that is used for the grid column label.

More than that

The short name is used as the grid column label for a UI element that is bound to the property that is annotated with this attribute. The Dynamic Data Insert.aspx and Edit.aspx page templates use the ShortName for the field label.

What should MS mean by "grid column label"?

I used that in my view, but obtained the Name instead of the ShortName

<table>
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Date) <!--Creation Date-->
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Name) <!--Project Name-->
            </th>
            <th></th>
        </tr>
    </thead>

for the defined Model like this

[Display(Name = "Creation Date", ShortName = "Date")]
public DateTime Date { get { return this.Timestamp.DateTime; } }

[Display(Name = "Project Name", ShortName = "Name")]
public string Name { get; set; }

Custom Helper

I already saw a very helpful answer on how to build a custom helper that could use it do the custom @Html.DisplayShortNameFor(), but I wonder what for it was created, if no possibility to use it without creating additional and, mainly, same shared by the community custom helpers, that, probably, should be included in the framework?! Am I missing something?

What are the "grid column label" and Insert.aspx and Edit.aspx templates (for the "asp.net core" usage)?

serge
  • 13,940
  • 35
  • 121
  • 205
  • The documentation you linked is for .NET Framework/ASP.NET, not for ASP.NET Core and/or .NET Core. aspx are code behind files of ASP.NET WebForms (and ASP.NET Core had a global.aspx too). Neither WebForms nor aspx are there anymore in ASP.NET Core – Tseng Jul 20 '17 at 17:06
  • @Tseng so where should I find that `ShortName` documentation for ASP.NET Core? – serge Jul 20 '17 at 17:09
  • [Introduction to ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/) – Anderson Pimentel Jul 20 '17 at 17:10
  • 2
    By Googling "ASP.NET Core docs" and picking the **first** result? – Tseng Jul 20 '17 at 17:10
  • @Tseng I am learning for weeks already from the ASP.NET Core MS documentation, but I ask now about the `DisplayAttribute.ShortName` attribute. Thanks. – serge Jul 20 '17 at 17:12
  • The api reference is on the same page Anderson linked, just scroll down (https://learn.microsoft.com/en-us/aspnet/core/api/). But DisplayAttribute isn't there, since it's not a ASP.NET Core class but part of corefx. In essence there is no code generation like there used to be in ASP.NET WebForms, so I'd be surprised to see that property used automatically unless you specifically call it with the custom extension method you already found out. – Tseng Jul 20 '17 at 17:17
  • @Tseng thanks for trying to help, but your links did't really brought light on the OP question... – serge Jul 20 '17 at 17:24
  • Like I said, `DisplayAttribute` isn't something ASP.NET Core specific. It resides in the `System.ComponentModel` namespace and is a set of generic attributes which can be used for multiple purposes, i.e. in WPF, WinForms, for Serialization (XML/JSON) or validation/localization (MVC). Just because the property is always there doesn't mean every consumer must use it. And unless the ASP.NET Core docs mention the property being used, it's most likely unused. But ASP.NET Core is open source, so feel free to dig through the source and see if its used anywhere – Tseng Jul 20 '17 at 17:36
  • As I understood from the Anderson answer, it was created and used for the Dynamic Data projects. Only people that works with this kind of project can understand what is about the MS documentation for that attribute. The documentation should be understood by all the people potentially using that attribute, including ASP.NET/ASP.NET Core users. – serge Jul 20 '17 at 18:16

1 Answers1

1

When it states that:

The Dynamic Data Insert.aspx and Edit.aspx page templates use the ShortName for the field label

It's probably about ASP.NET Dynamic Data:

ASP.NET Dynamic Data lets you create extensible data-driven Web applications by inferring at run time the appearance and behavior of data entities from the database schema and deriving UI behavior from it.

Never used it and seems not to be available on VS2017.

Probably, Nome, Email and Blog on the following screenshot:

Insert.aspx template

Anderson Pimentel
  • 5,086
  • 2
  • 32
  • 54
  • thanks for bringing the light on that DynamicData... What do you think are the *grid column labels* then? – serge Jul 20 '17 at 17:26
  • Updated the answer with a screenshot. – Anderson Pimentel Jul 20 '17 at 17:37
  • So, probably they use it only for that specific Dynamic Data type of projects... Worth mentioning that in the documentation because is very confuse now as is... :( – serge Jul 20 '17 at 17:40
  • In fact, attributes are just metadata. You can use it, as long as you make something with it somewhere else. In that case, they documented that they were using on DynamicData, but that doesn't mean anybody else is using it. – Anderson Pimentel Jul 20 '17 at 17:43
  • The description of the property in documentation is not clear. The documentation don't target specific users, so there are readers that never heard about Dynamic Data projects or the mysterious column labels... – serge Jul 20 '17 at 17:49