1

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

2
  • 1
    stackoverflow.com/questions/48833363/… Commented Nov 8, 2019 at 0:50
  • 1
    you seem to be taking an unnecessary complicated route here, consider just adding all the values of these text to a hidden input onsubmit. Commented Nov 8, 2019 at 1:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.