Right now I am trying to generate textareas to provide responses to a variable number of questions. I have finished the question side of things. This is my current solution for the responses side of things inside the cshtml I have.
@foreach (var question in ViewBag.Questions)
{
<div class="form-group">
<label asp-for="ResponseToList" class="control-label"> @question.QuestionText</label>
<textarea asp-for="ResponseToList" class="form-control" rows="3" required></textarea>
<span asp-validation-for="ResponseToList" class="text-danger"></span>
</div>
}
This creates the correct number of boxes with the correct questions as lables. However when I submit the form no matter how many textareas are generated only the first response is added to the array. Here is the code in the view-model
public List<string> Responses = new List<string>();
public string ResponseToList
{
get
{
return "Test";
}
set
{
Responses.Add(value.ToString());
}
}
Any help would be much appreciated