- Home
- Forum
- ASP.NET MVC - EJ 2
- Show enum string values in grid with remote datasource
Show enum string values in grid with remote datasource
Hello
Is it possible to show enum string names instead of int values for a grid with remote data source?
I have tried this:
https://www.syncfusion.com/forums/138484/enum-names-instead-of-int-values-in-asp-net-core-web-app-with-razor-pages
but it doesn't seem to work when I use DataManager with UrlAdaptor as a grid datasource.
Thanks, Tom
Is it possible to show enum string names instead of int values for a grid with remote data source?
I have tried this:
https://www.syncfusion.com/forums/138484/enum-names-instead-of-int-values-in-asp-net-core-web-app-with-razor-pages
but it doesn't seem to work when I use DataManager with UrlAdaptor as a grid datasource.
Thanks, Tom
SIGN IN To post a reply.
3 Replies
MS
Madhu Sudhanan P
Syncfusion Team
February 27, 2019 09:44 AM UTC
Hi Tomislav,
Greeting from Syncfusion.
We have validated the your query and checked with our end. By default, while creating MVC application(.Net core application uses Newtonsoft by default) it uses javascriptserializer so that it return enum values(int) instead of names. So we suggest you to use the below way to achieve your requirement.
In the below sample, we have serialize Json object using Newtonsoft serializer instead of Javascript serializer. Please refer the below code example and sample for more information.
|
public ActionResult UrlDatasource(Data dm)
{
var order = OrdersDetails.GetAllRecords();
var Data = order.ToList();
int count = order.Count();
// we have serialize the json object using newtonsoft
var SerializeData = Newtonsoft.Json.JsonConvert.SerializeObject(Data);
return dm.requiresCounts ? Json(new { result = SerializeData.Skip(dm.skip).Take(dm.take), count = count }): Json(SerializeData);
}
}
public class OrdersDetails
{
public OrdersDetails()
{
}
public OrdersDetails(int OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified, DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry, DateTime ShippedDate, string ShipAddress, state State)
{
. . . . .
this.ShipAddress = ShipAddress;
this.State = State;
}
public int? OrderID { get; set; }
public string CustomerID { get; set; }
. . . . .
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public state State { get; }
}
public enum state
{
[Display(Name = "Activated")]
Activated = 1,
[Display(Name = "Unactivated")]
Unactivated,
}
|
Regards,
Madhu Sudhanan P
TT
Tomislav Tustonic
February 27, 2019 04:03 PM UTC
Hello
Thanks for the reply. This works fine to display enum strings, however, now the filter (FilterType.CheckBox) doesn't work.
I have created a workaround, by fixing Where values in DataManagerRequest before applying to DbContext, but it would be nice to have it fixed in queryable operation.
Tom
Thanks for the reply. This works fine to display enum strings, however, now the filter (FilterType.CheckBox) doesn't work.
I have created a workaround, by fixing Where values in DataManagerRequest before applying to DbContext, but it would be nice to have it fixed in queryable operation.
Tom
MS
Madhu Sudhanan P
Syncfusion Team
February 28, 2019 06:34 AM UTC
Hi Tomislav,
Thanks for the suggestion. The string to Enum re-conversion should be handled at the server side before applying data operation.
Regards,
Madhu
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
TT Tomislav Tustonic
- Feb 26, 2019 07:22 PM UTC
- Feb 28, 2019 06:34 AM UTC