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 6382509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:31:53+00:00 2026-05-25T02:31:53+00:00

I’m trying to create asp mvc 3 page with a form with text fields

  • 0

I’m trying to create asp mvc 3 page with a form with text fields that are dynamically generated based on the number of object in a list that is in the model I passed into page controller. The problem I’m running into is that whenever I post to the controller the list maintains the values but not the names of the objects in the list. Here is an example:

The Model:

public class SomeModel
    {
        List<Field> fieldList;
        public SomeeModel()
        {
            fieldList = new List<Field>();
        }


        public string Name { get; set; }

        public List<Field> FieldList
        {
            get
            {
                return fieldList;
            }
        }

    }

The controller:

public ActionResult Preview()
{
    SomeModel model = new SomeModel();
    model.FieldList.Add( new Field { name = "test 1"});
    model.FieldList.Add( new Field { name = "test 2"});
    model.FieldList.Add( new Field { name = "test 3"});

    return View(model);
}

The View:

@using (Html.BeginForm()) {
    <div>
        <fieldset>
            <legend>Input Field List</legend>

            @for (var i = 0; i < Model.FieldList.Count(); i++)
            {
                <div class="editor-label">
                   @Html.Label(Model.FieldList[i].name)
               </div>
               <div class="editor-field">
                   @Html.TextBoxFor(model => Model.FieldList[i].value)
               </div>
            }

             <p>
                <input type="submit" value="Generate PDF" />
            </p>
        </fieldset>
    </div>

I saw a similar post here .NET MVC Razor Dynamic Form Generation but answer runs into the same issues as I got. Hope I’m being clear! If not I’ll post more info. Thanks!

  • 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-05-25T02:31:54+00:00Added an answer on May 25, 2026 at 2:31 am

    You could include those names as hidden fields. This way their values will be posted to the controller action:

    @for (var i = 0; i < Model.FieldList.Count(); i++)
    {    
        @Html.HiddenFor(model => Model.FieldList[i].name)
        ...
    }
    

    Also instead of writing those loops I would recommend you using editor templates:

    @model SomeModel
    @using (Html.BeginForm()) 
    {
        <div>
            <fieldset>
                <legend>Input Field List</legend>
                @Html.EditorFor(x => x.FieldList)
                <p>
                    <input type="submit" value="Generate PDF" />
                </p>
            </fieldset>
        </div>
    }
    

    and the corresponding editor template (~/Views/Shared/EditorTemplates/Field.cshtml) which will be rendered for each element of the FieldList collection:

    @model Field
    @Html.HiddenFor(model => model.name)
    <div class="editor-label">
        @Html.LabelFor(model => model.value, Model.name)
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(model => model.value)
    </div>
    

    Another possibility instead of using hidden fields would be to externalize those names into some data store and then have a repository which would return them. So in your two actions you would simply query this repository for the names. Because they cannot be changed it is not necessary to include them in the HTML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.