Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:45:00+00:00 2026-06-07T16:45:00+00:00

I am building an MVC form with a bunch of textboxes. However, my model

  • 0

I am building an MVC form with a bunch of textboxes. However, my model requires a list of strings. What I’m trying to do is have it so when the user hits submit, before the form posts, it takes all of the values in the text box, adds it to a List and appends it to the model for submitting. I’m stuck at how I would be able to do this?

The reason I need to do this is that I need the form to be dynamic in that the # of fields can grow and the page adapts to that. I can’t hardcode the individual fields into the model as the model would need to adapt to the length of the form.

Here’s my code so far:

The HTML

@using (Html.BeginForm(new { id = "feedbackForm" }))
{
<fieldset>

    @foreach (Feedback_Num_Questions questionForm in FeedbackSurveyQuestions)
    {
        string textBoxID = "feedbackq";

        questionNumberTextBoxes++;

        textBoxID = textBoxID + questionNumberTextBoxes.ToString();

        <input type="text" id="@textBoxID" />
    }

    <input type="text" id="txtAdditionalComments" />

    <input type="submit" value="Create" name="btnFeedbackSubmit" id="btnSubmitFeedbackForm" />

    </fieldset>
}

The Model:

    public class PostCourseFeedbackModel
    {
        public List<string> responseList { get; set; }
        public decimal pelID { get; set; }
        public string employeeid { get; set; }
    }

Thanks for the help!

UPDATE: after getting a response from FLEM, I revised my code a bit to this. Still not quite working, but was hoping somebody could spot out the issue:

HTML:

 @using (Html.BeginForm(new { id = "feedbackForm" }))
 {
<fieldset>

    @{

    int i = 0;



    foreach (Feedback_Num_Questions questionForm in FeedbackSurveyQuestions)
    {
        i++;
        string textBoxID = "feedbackq" + i.ToString();
        @Html.TextBoxFor(m => m.responseList[i], new { @id = textBoxID });
    }



    <input type="submit" value="Create" name="btnFeedbackSubmit" id="btnSubmitFeedbackForm" />
        }
    </fieldset>
 }

The model remained unchanged…

UPDATE – As requested by flem, I am posting my action. However this is a barebones action as I have yet to code what I plan to do with the data…

    [HttpPost]
    public ActionResult PostCourseFeedback(PostCourseFeedbackModel feedback)
    {

         return RedirectToAction("FeedbackSubmitted", "Feedback", new { status = "success" });
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:45:02+00:00Added an answer on June 7, 2026 at 4:45 pm

    I would let the model binder do that hard work for you.

    @using (Html.BeginForm(new { id = "feedbackForm" }))
    {
        <fieldset>
        @{
            int i = 0;
            foreach (Feedback_Num_Questions questionForm in FeedbackSurveyQuestions)
            {
                @Html.EditorFor(m => m.responseList[i++])
            }
        }
    
            <input type="text" id="txtAdditionalComments" />
    
            <input type="submit" value="Create" name="btnFeedbackSubmit" id="btnSubmitFeedbackForm" />
    
        </fieldset>
    }
    

    Here’s a working sample:

    Model and controller:

    using System.Collections.Generic;
    using System.Web.Mvc;
    
    namespace MvcApplication1.Controllers
    {
        public class MyController : Controller
        {
            public ActionResult MyAction(MyModel Model)
            {
                return View(Model);
            }
    
        }
        public class MyModel
        {
            public List<string> TextFields { get; set; }
        }
    }
    

    View:

    @model MvcApplication1.Controllers.MyModel
    
    @using (Html.BeginForm())
    {
        for (int i = 0; i < 3; i++)
        {
            string id = "txt" + i.ToString();
    
            @Html.TextBoxFor(m => m.TextFields[i], new { id = id })
        }
    
        <input type="submit" value="Post" />
    
        if (Model.TextFields != null)
        {
            foreach (string textField in Model.TextFields)
            { 
                <div>Posted Field: @textField</div>
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an MVC 3 website. I have a model looking like this: public
I have a simple form on an ASP.NET MVC site that I'm building. This
I'm building an advanced search form for my ASP.NET MVC app. I have a
I am building a wizard using asp.net mvc. currently when the user hits next
I am building a simple user registration form using the MVC design pattern, in
I am building an MVC 3 application which uses the standard Model validation attributes
I'm building a Spring MVC app with Spring 3.0.3. I have data binding of
Hello I am building a form in a mvc system view, and i want
I'm building an MVC3 application and would like to have a form with a
I'm building a site in MVC and the View Model I am passing to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.