I have a model as follows:
public class TestResultModel
{
public bool Successful { get; set; }
public string ErrorMessage { get; set; }
}
public class TestResultListModel : List<TestResultModel>
{
public int TotalTestCases { get { return base.Count; } }
public int TotalSuccessful { get { return base.FindAll(t => t.Successful).Count; } }
}
I return this TestResultListModel
from an ApiController
:
var testResultListModel = new TestResultListModel();
foreach (var testCaseId in new int[] {1,2,3,4})
{
var testResultModel = new TestResultModel
{
Successful = true,
ErrorMessage = "STRING"
};
testResultListModel.Add(testResultModel);
}
return testResultListModel;
When I inspect the JSON result it does contain all the TestResultModel
s, but the properties on the TestResultListModel
(TotalTestCases
and TotalSuccesful
) are not visible.
How can I also include these values in the JSON-serialized object?
What I tried is using JSON.NET
and decorating the properties with the attribute [JsonProperty]
, this was unsuccessful.