ASP.NET Dynamic Data – Hide/show table or column


I am once again working with a helper project, which I need to have several people add data to a database, used with an upcoming release. Why use Dynamic Data? Well, it is simple and easy to get going, once you have your data model, for which I generally use the Entity Framework. Anyway, I had forgotten a few of the data annotations you can use with the metadata, including how to hide or show a table or column. However, it is really simple, once you look at the System.ComponentModel.DataAnnotations namespace.

The ScaffoldTable and ScaffoldColumn attributes can be used for this purpose, as shown here:

[ScaffoldTable(true)]
[MetadataType(typeof(Culture_Metadata))]
public partial class Culture
{
    internal class Culture_Metadata
    {
        [ScaffoldColumn(false)]
        public bool Id { set; get; }
    }
}

The table Culture is shown whereas the column Id isn’t shown, when using the scaffolding feature of Dynamic Data.

Advertisements