We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

In 17.2.50 templates seem to be ignoring ModelType and passing the type declared in TValue

Thread ID:

Created:

Updated:

Platform:

Replies:

147438 Sep 10,2019 11:17 PM UTC Sep 13,2019 05:32 AM UTC Blazor 5
loading
Tags: Grid
Jeffrey West
Asked On September 10, 2019 11:17 PM UTC

The context passed to Templates now seems to be of type TValue instead of the type passed in ModelType. This was working fine in previous builds. Is this a known issue?

Just for a little more context, I am rendering a string of objects whose Type I don't know until runtime so my TValue is an interface type. But for the templates, I was passing a new concrete type to ModelType with matching Property Names. This was all working very well until the latest build.

Thanks,

Jeff


Vignesh Natarajan [Syncfusion]
Replied On September 11, 2019 09:27 AM UTC

Hi Jeffrey,  
  
Thanks for contacting Syncfusion support.  
  
Query: “The context passed to Templates now seems to be of type TValue instead of the type passed in ModelType 
  
To replicate your issue at our end, we have prepared a sample with two different classes (one class for TValue and another one for ModelType) with the same properties to bind it to Grid. We can reproduce the reported issue while accessing the values in the template context.  
  
Previously (till 17.2.0.47v) we will be serializing the string objects of template context by matching it with ModelType class. While using this approach we are not able to properly serialize the properties such as read-only, get-only properties, DateTimeOffset, TimeSpan, etc.  
  
So from our latest Nuget release (17.2.0.50) we have modified this approach to bind those properties correctly by using the original object without serialization. Hence in the latest update, reported behavior occur. So here after it will not be possible to match the template context directly with ModelType. To overcome this behavior, we need to serialize manually from the context. 
  
Refer the below code example  
  
<GridColumn HeaderText="Employee Image" TextAlign="TextAlign.Center" Width="120"> 
            <Template> 
                @{ 
                    var employee = JsonConvert.DeserializeObject<EmployeeData>(JsonConvert.SerializeObject(context)); // manually serialize the object to respective types. 
                    <div class="image"> 
                       <button>@employee.FirstName</button> 
                    </div> 
                } 
            </Template> 
        </GridColumn> 
      
For your convenience we have attached the sample with above solution. Kindly download the sample from below  
  
 
Please find the release notes regarding this changes from below link  
 
 
Please get back to us if you have further queries.    
  
Regards, 
Vignesh Natarajan. 
 


Jeffrey West
Replied On September 11, 2019 05:09 PM UTC

Thanks for the quick reply. Glad to know it is an intentional change and not a bug. Perhaps you can update the documentation to no longer say that ModelType is required for templates. 

Thanks,

Jeff

Vignesh Natarajan [Syncfusion]
Replied On September 12, 2019 07:20 AM UTC

Hi Jeffrey,  
  
Thanks for the update.  
  
Query: “Perhaps you can update the documentation to no longer say that ModelType is required for templates” 
  
While using Templates in Grid, it is necessary to define ModelType property in EjsGrid to serialize the objects inside the templates. The modified approach (from 17.2.0.50) for Template context will be applicable only for local data (List / IEnumerable) which uses Blazor adaptor for binding the dataSource. Because in local data only, entire objects will be returned.   
  
For all other Adaptors such as Web API and OData, the data (object) will be fetched from their own service which will be in form of string. So here approach will be same as in older version. So kindly use the solution suggested in the previous update to resolve the issue while using two different classes from TValue and ModelType.       
  
Regards, 
Vignesh Natarajan. 


Jeffrey West
Replied On September 12, 2019 04:29 PM UTC

Ah. That makes sense. Thanks again for the quick reply. 

Jeff

Renjith Singh Rajendran [Syncfusion]
Replied On September 13, 2019 05:32 AM UTC

Hi Jeffrey, 

Thanks for your update. 

We are happy to hear that your requirement has been achieved. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon