list data not showing in return json api

Viewed 75

hi when i try to get data from an api request the list data is missing

[Route("/Calculators/{id}")]
[HttpGet("{id}")]       
public CalcRequiredInputs Get(int id)
{    
    using (var context = new PiContext())
    {
        var calReqIn = new CalcRequiredInputs();
        calReqIn.CalObj  = context.TaskCalculators.Where(e => e.Id == id).ToList().ToList();
        calReqIn.ListOfRequiredInputs.Append("Dom");
        return calReqIn;
    }
}

public class CalcRequiredInputs
{        
    public List<string> ListOfRequiredInputs = new List<string>();
    public List<Calculator>? CalObj { get; set; }
}

public class Calculator
{
    public int Id { get; set; }
    public string CalculatorName { get; set; } = null!;
}

Output

{"calObj":[{"id":1,"calculatorName":"M2"}]}

ListOfRequiredInputs is missing

1 Answers

This is likely to because ListOfRequiredInputs is a field and not a property. Try the following:

public class CalcRequiredInputs
{
    public List<string> ListOfRequiredInputs {get;} = new List<string>();
    public List<Calculator>? CalObj { get; set; }
}
Related