This is a migrated thread and some comments may be shown as answers.

[Solved] Grid Column Scaffolding And DataAnnotations

5 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jason Tully
Top achievements
Rank 1
Jason Tully asked on 23 Feb 2010, 03:18 PM

Does the  ASP,NET MVC Grid support column scaffolding and data annotations?  

We are building a product that uses Html.DisplayForModel() and Html.EditorForModel() to automatically render our views from the underlying Model.  Annotations are provided by registering a custom type descriptor provider for our model types and calling TypeDescriptor.GetProperties( ) for the current model instance.  (Both Html.DisplayForModel and EditorForModel build their respective UI's by this method).   Is there a way to make the grid annotation aware when auto generating columns from the Model?  Ideally, we would like to be able to specify the column's header using an annotation as well as the visibility of the column, add/edit/delete buttons etc...

Thanks
Jason T

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 23 Feb 2010, 03:24 PM
Hi Jason Tully,

The Q1 2010 Futures has some preliminary support for DisplayFor and EditorFor. Both are used for rendering the grid records in display and edit mode. The column header should also be datannotations aware. The only thing which will not work is command columns because they are created as a Command column.

I suggest you download the futures build and give it a spin. We will appreciate your feedback.

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jason Tully
Top achievements
Rank 1
answered on 23 Feb 2010, 03:52 PM
Is the latest release using ASP.NET MVC RC2
0
Atanas Korchev
Telerik team
answered on 23 Feb 2010, 04:36 PM
Hi Jason Tully,

Yes, it is. I forgot to mention that the MVC grid is using the data annotation attributes for validation as well.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jason Tully
Top achievements
Rank 1
answered on 23 Feb 2010, 05:16 PM
I think I discovered a bug.  Looking at the source code for GridBoundColumn i noticed that even though the MVC2 code section was executing, the Title of the field was always being set using memberExpression.Member.Name.SplitPascalCase();  I changed the compilation directives as seen below and everything began working correctly.  I have the ScaffoldColumn attribute set to false for columns I wish to hide and the DisplayNameAttribute set to the text I want displayed as the column header.  Is there a way to order the columns as well?  In our annotation framework, we have an Order property and I order the collection of properties returned from TypeDescriptor.GetProperites using this value.  How does the Grid reflect the list of properties to display?

#if MVC2 
            Metadata = ModelMetadata.FromLambdaExpression(expression, new ViewDataDictionary<TModel>()); 
            Title = Metadata.DisplayName; 
            Format = Metadata.DisplayFormatString; 
            Visible = Metadata.ShowForDisplay; 
#else 
 
            MemberExpression memberExpression = expression.ToMemberExpression(); 
             
            if (memberExpression == null
            { 
                throw new InvalidOperationException("Only property and field expressions are supported"); 
            } 
 
            MemberInfo member = memberExpression.Member; 
 
            if (member.MemberType == MemberTypes.Property || member.MemberType == MemberTypes.Field) 
            { 
                Title = member.GetDisplayName(); 
                Format = member.GetFormat(); 
            } 
 
            if (string.IsNullOrEmpty(Title)) 
            { 
                Title = memberExpression.Member.Name.SplitPascalCase(); 
            } 
#endif 



0
Atanas Korchev
Telerik team
answered on 24 Feb 2010, 07:54 AM
Hello Jason Tully,

Indeed there is a problem now how metadata is inferred. I will fix it right away.

You can check the GridColumnGenerator class which is responsible for the automatic generation of columns.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Jason Tully
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jason Tully
Top achievements
Rank 1
Share this question
or