WebGrid and EF4 Attributes

Can I use DataAnnotations attributes with the MVC3 WebGrid extension?

I use some DataAnnotations EF4 attributes, such as [ScaffoldColumn (true)] and [Display (Description = "Name", Prompt = "Enter name", ShortName = "Name")]. But this does not affect WebGrid.

So, how can I use DataAnnotations attributes using WebGrid, if possible?


UPDATE OK, Darin Dimitrov answers my question. And couse is +1. But MVCContrib is much better for work than WebGrid. It is my choice.

+4
source share
1 answer

WebGrid Helper does not use DataAnnotations. You can customize the columns and use the editor / display templates in them if you want these attributes to have some kind of effect. You can also have something among the lines:

@{ var grid = new WebGrid(Model); } @grid.GetHtml( columns: ViewData .ModelMetadata .Properties .Single() .Properties .Select( p => grid.Column( columnName: p.PropertyName, header: p.ShortDisplayName ) ) ) 
+6
source

Source: https://habr.com/ru/post/1339467/


All Articles