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. Image for the cookie policy date
close icon

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

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


5 Replies

VN Vignesh Natarajan Syncfusion Team 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. 
 



JW Jeffrey West 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


VN Vignesh Natarajan Syncfusion Team 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. 



JW Jeffrey West September 12, 2019 04:29 PM UTC

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

Jeff


RS Renjith Singh Rajendran Syncfusion Team 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. 


Loader.
Up arrow icon