I had the same problem. I am returning an object for the grid. It has some properties, such as lines, page, total, etc. Installing a resolution device on a camel case solves the problem for properties at the top level. But if any property contains a list of objects with property names with pascal, this does not change their case.
So, here is what I did to solve this problem.
Grid object with data to return
[DataContract] public class GridProperties<T> { [DataMember] public List<T> Rows { get; set; } [DataMember] public int Records { get; set; } [DataMember] public int Total { get; set; } [DataMember] public int Page { get; set; } }
Here Lines contain a list of objects. Here I returned a list of model objects. The model class is as follows:
public class ClientListModel { [DataMember(Name = "clientId")] public int ClientId { get; set; } [DataMember(Name = "firstName")] public string FirstName { get; set; } [DataMember(Name = "lastName")] public string LastName { get; set; } [DataMember(Name = "startDate")] public DateTime? StartDate { get; set; } [DataMember(Name = "status")] public string Status { get; set; } public ClientListModel() {} }
And below shows how I returned JSON data from my API controller
[HttpGet] public GridProperties<ClientListModel> GetClients(int page) { const int rowsToDisplay = 10; try { IEnumerable<ClientListModel> clientList = null; using (var context = new AngularModelConnection()) { clientList = context.Clients.Select(i => new ClientListModel() { ClientId = i.Id, FirstName = i.FirstName, LastName = i.LastName, StartDate = i.StartDate, Status = (i.DischargeDate == null || i.DischargeDate > DateTime.Now) ? "Active" : "Discharged" }); int total = clientList.Count();
Attribute
[DataMember(Name ="")] indicates which name should be used for the property when the object is serialized.
Hope this helps!
Mayank Sharma Dec 18 '14 at 8:08 2014-12-18 08:08
source share