Syncfusion Grid not using custom DataAnnotationsModelMetadataProvider

Hi all,

i am currently testing Syncfusion MVC for my Project.

I added the nuget package and followed the instructions.

I have a grid working and it is showing all values correctly,
but the grid shows the wrong column names.

the old ASP.Net MVC "Grid" was a table with header:
<tr>
        <th>
            @Html.DisplayNameFor(model => model.DateCreated)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.DateModified)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ObjectType)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
    </tr>


Now i jhave implemented my Table with EJ()...:
  Html.EJ().Grid<Weltmeyer.UpRent2.Data.Entities.Flat>("test").Datasource(Model)
        .Columns(c =>
        {
            c.Field(m => m.Name).Add();
            c.Field(m => m.ObjectType).Add();

        })
But it is showing the wrong Column Names.

The right Column Names come from my CustomDataAnnotationsModelMetadataProvider.

Is Syncfusion ignoring this MetaDataProvider? (
class CustomModelMetadataProvider : DataAnnotationsModelMetadataProvider
    {
     

        protected override ModelMetadata CreateMetadata(
                                 IEnumerable<Attribute> attributes,
                                 Type containerType,
                                 Func<object> modelAccessor,
                                 Type modelType,
                                 string propertyName)
        {...}
)

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 5, 2018 12:17 PM UTC

Hi Jan,  
 
Thanks for contacting Syncfusion Support.  
 
Please share the following details to proceed further on this, before proceeding on this.  
 
  1. Model details of the “Weltmeyer.UpRent2.Data.Entities.Flat
  2. Code example of Grid along with the Model
  3. Version of the Essential Studio
  4. Screenshot with the expected results and actual results
 
Regards,  
Seeni Sakthi Kumar S. 



JA Jan September 5, 2018 12:47 PM UTC

Hi,

i have a demo Project attached which shows the Problem.

Is this enough for you to test?

Attachment: SyncFusionTest_17289d40.zip


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 10, 2018 08:57 AM UTC

Hi Jan,  

In our MVC source, we have not inherited the DataAnnotationsModelMetadataProvider for dataAnnotation class rather we have inherited the mvcMetaDataProvider.  So we cannot directly override the  DataAnnotationsModelMetadataProvider to change the metadata for our controls. We need to override our custom MetaDataProvider class in the application level. Kindly refer to the following code snippet. 

[DemoController]  
        public ActionResult Index()  
        {  
            EssentialJavaScript.MetadataProvider = new CustomeModelMetaProvider();  
            return View(GetData());  
        }  
   

[CustomModelMetaProvider]  
using Syncfusion.MVC.EJ.Extension;  
using Syncfusion.JavaScript;  
using System.Reflection;  
  
namespace SyncFusionTest  
{  
    public class CustomeModelMetaProvider : IMetadataProvider  
    {  
        public Metadata Read(PropertyInfo property)  
        {  
            return property.GetMetadata();  
        }  
  
        public Dictionary<string, Metadata> ReadFromType(Type modelType)  
        {  
            var properties = modelType.GetProperties();  
            var res = new Dictionary<string, Metadata>();  
  
            foreach (var prop in properties)  
            {  
                var a = prop.GetMetadata();  
                a.HeaderText = $"MetaDisplayNameFor({prop.Name})";  
                res.Add(prop.Name, a);  
            }  
  
  
            return res;  
        }  
  
        public Metadata FromType(Type modelType, string propertyName)  
        {  
            var prop = modelType.GetProperty(propertyName);  
  
            return prop != null ? prop.GetMetadata() : null;  
        }  
    }  
}  


Regards, 
Seeni Sakthi Kumar S. 


Loader.
Up arrow icon