I have a list of string data, I want to add some values there and see them. There is a method for adding data and another method for printing. after adding some data get an empty list during print.
Here Is my code
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
private List<string> dataList = new List<string>();
[HttpGet]
public async Task<IActionResult> GetData()
{
return Ok(dataList);
}
[HttpPost]
public async Task<IActionResult> AddData()
{
var testData = new List<string>() { "ab", "cd", "efg" };
foreach(var data in testData)
{
dataList.Add(data);
}
return Ok();
}
}