How can I use DisplayName data annotations for column headers in WebGrid?

I have a Car class that I'm trying to display in an MVC 3 view using the WebGrid helper. Below are the Car and it's metadata class.

Car class:

[MetadataType(typeof(CarMetadata))]
public partial class Car
{
    // car implementation
}

Car metadata class:

public class CarMetadata
{        
    [DisplayName("Car Name")]
    [StringLength(100, ErrorMessageResourceType = typeof(ValidationText), ErrorMessageResourceName="CarNameDescriptionLength")]
    [Required]
    public string CarName { get; set; }    
}

View contents:

@model List<Car>
...
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 10);
grid.Pager(WebGridPagerModes.NextPrevious);

@grid.GetHtml(
    htmlAttributes: new { id = "grid" },
    columns: grid.Columns(
        grid.Column("CarName", ?????)
    ));

GOAL: I'd like to figure out how to use the DisplayName data annotation as the column header text in the WebGrid (?????). Does anyone know how this is accomplished?

Thanks in advance!

13
задан 80bower 9 March 2011 в 18:55
поделиться

0 ответов

Другие вопросы по тегам:

Похожие вопросы: