Dynamic Data - How to show the Primary Key field in the List

asp.net, dynamic-data

Solution

After spending most of the day researching, I have another answer that is probably more "correct". From what I can see, this is on a per table basis (meaning you'd have to do this once per table)

Using the ScaffoldColumn attribute:

I extended the class that is automatically generated for the table (StatusCodes) using a partial class as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.DynamicData;
using System.ComponentModel.DataAnnotations;

namespace ScholarshipAdmin
{
    [MetadataType(typeof(StatusCodesMetaData))]
    public partial class StatusCodes 
    {

    }

    public class StatusCodesMetaData
    {
        [ScaffoldColumn(true)] 
        public object StatusCode;
    }
}

Problem

I'm finally digging into Dynamic Data (long overdue). I notice that when I'm viewing the web site, on the main table lists, the primary key field is not displayed. For example, I have a table that holds Status Codes, with two fields. ``` StatusCode int identity Primary Key StatusCodeDescription varchar(25) ``` On my web site's StatusCodes/List.aspx page, only the StatusCodeDescription shows. I realize that I can't edit the primary key, but I would like to show it. Is this possible with Dynamic Data? I can think of some workarounds myself, and in all honesty, I could dig into the documentation further to find it myself, but I'm hoping that someone with more experience knows the answer and can save me some time looking. A link to the appropriate documentation would even be good.

Original source