Enum value as string

Hello.

I've been trying to get the enum value as string into the grid, using .NET Core web application, and setting up the grid using tag helper, with a child grid defined in C#. I've found some examples of how to do it, but none of them appear to be working.
I've tried changing the default serializer to Newtonsoft.Json, decorate the class and enum values itself with appropriate attributes, but the grid still renders column as int value of the enum.
The template ${column} also produces the int value of the enum, but I'd like the string value instead.

If i changed the return type of controller from View(viewModel) to Json(viewModel), the returned json string is properly formatted and enums are rendered as string, but if i return a view, and setup the grid using tag helper, the rendered json string that's set as data source of the grid in the page source is rendering enums as int.

3 Replies

MS Manivel Sellamuthu Syncfusion Team September 14, 2020 08:20 AM UTC

Hi Tomasz, 

Greetings from Syncfusion support. 

Based on your query we found that want to display the string value for the enum in the Grid. In this you also mentioned that when you changed the return type of the controller (View(viewModel) to Json(viewModel)) it display the string value.  

Before we proceed with your query we need the following details, 

1. Share the complete Sever/client side Grid rendering code. 

2. Screenshot and video demonstration of the issue. 

3. Sample code/data for the enum property 

Regards, 
Manivel 



TO Tomasz September 14, 2020 11:08 AM UTC

I've found a problem- it was on my end.
I accidentially used JsonConverter attribute from System.Text.Json package instead of Newtonsoft.Json.

In the 'Grid sample 2' page I found out that field attribute decoration with JsonSerializer class takes priority over default MVC serializer (see class Startup in the attached example). Despite the fact that controller return proper data with ajax call, the data in the Enum Property2 column is rendered as int value, instead of a name. For that particular example, I used System.Text.Json serializer explicitly.

Is this intentional, or a bug ? Because of this behaviour I posted the problem in the first place, since I was experimenting with setting up default serializer to Newtonsoft.Json, and I didn't seem to have an effect on the output.

If that is intentional, I suggest writing it up in the docs, for future reference, and ask, if it's possible to add support for System.Text.Json serialized the same way ? :)


Attachment: WebApplication1_fbbb08d9.zip


MS Manivel Sellamuthu Syncfusion Team September 21, 2020 01:25 PM UTC

Hi Tomasz, 

Sorry for the delay getting back to you. 

We have checked your query and we do not have any immediate plan to replace NewtonSoft with Microsoft Json library. We will intimate you if we have any changes in this and we request your support for this until then. we have logged a feature request on this and it can be tracked through our feedback portal below.  


Please cast your vote to make it count. We will prioritize the features every release based on the demands.  

If you have any more specification/suggestions to the feature request you can add it as a comment in the portal. 

Regards, 
Manivel 


Loader.
Up arrow icon