ASP.NET MVC showing text from Enum column in jquery DataTables?
ASP.NET MVC showing text from Enum column in jquery DataTables?
parismiguel
Posts: 7Questions: 3Answers: 0
How should I show text from a enum column instead of its value in a jQuery DataTable, without losing its value as I'll be using it later for editing purposes?
Given a Class:
public class Person
{
[Key]
public int PersonUID { get; set; }
public string FirstName { get; set; }
public EstadoPersona Status { get; set; }
}
And a Enum:
public enum EstadoPersona
{
Active, Inactive
}
I'm populating a jQuery DataTable using the following action from Controller:
public ActionResult List()
{
var data = db.People.Select(
a => new
{
a.FirstName,
a.Status,
a.PersonUID
}).OrderByDescending(a => a.PersonUID).ToList();
return Json(data, JsonRequestBehavior.AllowGet);
}
And this is my **DataTable **set up:
$("#tblPersons").DataTable({
processing: true,
dom: 'Brtip',
ajax: {
type: "POST",
url: "/People/List",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: function (data) {
return data = JSON.stringify(data);
},
dataSrc: "",
error: function (jqXHR, textStatus, errorThrown) {
debugger; alert("ajax error: " + textStatus);
}
},
columns: [
{data: "FirstName" },
{ data: "Status"},
{ data: "PersonUID" }
],
rowId: 'PersonUID',
},
order: [],
});
This discussion has been closed.
Answers
Did you ever get this resolved?