- Home
- Forum
- ASP.NET MVC
- Problem setting Enum text values in Grid
Problem setting Enum text values in Grid
Hello,
I'm trying to show Enum text values in a grid control following the tutorial provided in this site:
But even the grid shows the numeric values. Here's is my code for reference:
View
@using Syncfusion.JavaScript.Shared.Serializer
@using ######################
@{
DataManagerConverter.Serializer = new DMSerial();
}
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.AllowPaging() /*Paging Enabled*/
.AllowFiltering()
.Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).Width(75).Add();
col.Field("FirstName").HeaderText("FirstName").Width(75).Add();
col.Field("LastName").HeaderText("LastName").Width(75).Add();
col.Field("Title").HeaderText("Title").Width(110).Add();
col.Field("Unit").HeaderText("Unit").Width(75).Add();
}))
Controller
using System.Web.Mvc;
using System.Runtime.Serialization;
using Syncfusion.JavaScript.Shared.Serializer;
using System.Collections.Generic;
using System.Web.Script.Serialization;
namespace ################
{
public class DMSerial : IDataSourceSerializer
{
public string Serialize(object obj)
{
return Serialize(obj, null);
}
public string Serialize(object obj, object settings = null)
{
var str = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
return str;
}
}
public class HomeController : BaseController
{
public static List<Details> obj = new List<Details>();
public ActionResult Index()
{
var DataSource = GetInversedData();
ViewBag.datasource = DataSource;
return View();
}
public static List<Details> GetInversedData()
{
List<Details> obj = new List<Details>();
for (var i = 0; i < 1; i++)
{
obj.Add(new Details() { OrderID = 10001, FirstName = "Nancy", LastName = "Davolio", Title = "Sales Representative", Unit = UnitOfMeasure.g });
obj.Add(new Details() { OrderID = 10002, FirstName = "Andrew", LastName = "Fuller", Title = "Vice President, Sales", Unit = UnitOfMeasure.Kg });
obj.Add(new Details() { OrderID = 10003, FirstName = "Janet", LastName = "Leverling", Title = "Sales Representative", Unit = UnitOfMeasure.l });
obj.Add(new Details() { OrderID = 10004, FirstName = "Margaret", LastName = "Peacock", Title = "Sales Representative", Unit = UnitOfMeasure.Nr });
obj.Add(new Details() { OrderID = 10005, FirstName = "Steven", LastName = "Buchanan", Title = "Sales Manager", Unit = UnitOfMeasure.Nr });
obj.Add(new Details() { OrderID = 10006, FirstName = "Michael", LastName = "Suyama", Title = "Sales Representative", Unit = UnitOfMeasure.g });
obj.Add(new Details() { OrderID = 10007, FirstName = "Robert", LastName = "King", Title = "Sales Representative", Unit = UnitOfMeasure.Kg });
obj.Add(new Details() { OrderID = 10008, FirstName = "Laura", LastName = "Callahan", Title = "Inside Sales Coordinator", Unit = UnitOfMeasure.l });
}
return obj;
}
public class Details
{
public int OrderID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
public UnitOfMeasure Unit { get; set; }
}
public enum UnitOfMeasure
{
[EnumMember(Value = "Number")]
Nr = 0,
[EnumMember(Value = "Kilogram")]
Kg = 1,
[EnumMember(Value = "Gram")]
g = 2,
[EnumMember(Value = "Liter")]
l = 3
}
}
}
Att,
SIGN IN To post a reply.
2 Replies
ER
Erik
April 24, 2019 02:00 PM UTC
Hi,
Please, move this thread to ASP.NET MVC - EJ1 as this problem happens with the EJ1.
Thanks!
VN
Vignesh Natarajan
Syncfusion Team
April 25, 2019 02:34 PM UTC
Hi Luis,
Thanks for contacting Syncfusion forums
Query: “I'm trying to show Enum text values in a grid control following the tutorial provided in this site:”
We have validated the defect you have initiated with us. Thank you for the taking the time to report the issue and helping us improve our product. At Syncfusion we are committed to fixing all the validated defect (subject to technological feasibility and Product Development Life Cycle) and including the fix for the defect in our subsequent 2019 Volume 2 release. You can track the current status of your request, review the resolution timeline and contact us for any further inquiries through this link.
Note: To view the above feedback, kindly login into your account.
Till then we appreciate your patience.
Till then we appreciate your patience.
Regards,
Vignesh Natarajan
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
ER Erik
- Apr 24, 2019 01:57 PM UTC
- Apr 25, 2019 02:34 PM UTC