I'm trying to construct some paging for a WebApi I'm writing.
I need to return back the total of all records along with the request display amount in JSON.
EDIT
Ok, so taking your adivce onbaord, i serialize my object, but i stil get the black slashes.
"[
{
\"RowNumber\": 1,
\"TotalRows\": 10,
\"TotalDisplayRows\": 10
\"Sender\": \"MNBLGB2L\"
},
{
\"RowNumber\": 2,
\"TotalRows\": 10,
\"TotalDisplayRows\": 10
},
{
\"RowNumber\": 3,
\"TotalRows\": 10,
\"TotalDisplayRows\": 10
},
{
\"RowNumber\": 4,
\"TotalRows\": 10,
\"TotalDisplayRows\": 10
},
{
\"RowNumber\": 5,
\"TotalRows\": 10,
\"TotalDisplayRows\": 10
}
]"
Code that creates this is :
List<Summary> results = MtFacade.GetSummary(query);
string jsonData = JsonConvert.SerializeObject(results);
return jsonData;
the Summary class is :
[Serializable]
public class Summary
{
public int RowNumber { get; set; }
public int TotalRows { get; set; }
public int TotalDisplayRows { get; set; }
}
So, using both Javascript serializer and JSON produces the back slashes:
***EDIT ****
GetSummary is in my Business Layer, which is an interface from the datalayer:
public static List<Summary> GetSummary(string query)
{
return MessageRepository.GetSummary(query);
}
this is the interface:
List<Summary> GetSummary(string query);
which is used in the datalayer, taking advantage of dapper:
public List<Summary> GetSummary(string query)
{
using (var block = new TransactionBlock())
{
var results =
TransactionBlock.Connection.Query<Summary>(query, transaction: TransactionBlock.Transaction)
.ToList();
block.Commit();
return results;
}
}