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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:02:23+00:00 2026-05-28T13:02:23+00:00

I am creating a dynamic list of text boxes. when the user submits the

  • 0

I am creating a dynamic list of text boxes. when the user submits the value in the fields come back null. I think I’m missing something.

This is my product model:

public class EnqProduct
{
    public string Id { get; set; }
    public string Product { get; set; }
    public string Quantity { get; set; }
}

This is the page model which includes a list of the above.

public IList<EnqProduct> EnqProduct { get; set; }

This is how I am setting the model:

IList<EnqProduct> items2 = Session["enquiry"] as IList<EnqProduct>;
var EnquiryModel = new Enquiry { 
       EnqProduct = items2  
};      
return View(EnquiryModel);

and this is how I display the fields:

foreach (var item in Model.EnqProduct)
{
 <tr>
   <td>
      <span class="editor-field">
         @Html.TextBox(item.Id, item.Product)
         @Html.ValidationMessageFor(m => m.A1_Enquiry)
      </span>  
      <br><br>                              
    </td>
    <td>
      <span id = "field" class="editor-field">
         @Html.TextBox(item.Id, item.Quantity)
      </span>      
      <br><br>                              
    </td>
  </tr>
 }

When the user submits the fields go back to the controller null?

  • 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-28T13:02:23+00:00Added an answer on May 28, 2026 at 1:02 pm

    I would recommend you using editor templates and replace your foreach loop with the following:

    @model Enquiry
    <table>
        <thead>
            <tr>
                <th>product name</th>
                <th>quantity</th>
            </tr>
        </thead>
        <tbody>
            @Html.EditorFor(x => x.EnqProduct)
        </tbody>
    </table>
    

    and then define an editor template which will automatically be rendered for each element of the EnqProduct collection (~/Views/Shared/EditorTemplates/EnqProduct.cshtml):

    @model EnqProduct
    <tr>
        <td>
            @* We include the id of the current item as hidden field *@
            @Html.HiddenFor(x => x.Id)
    
            <span class="editor-field">
                @Html.EditorFor(x => x.Product)
                @Html.ValidationMessageFor(x => x.Product)
            </span>  
        </td>
        <td>
            <span id="field" class="editor-field">
                @Html.EditorFor(x => x.Quantity)
            </span>      
        </td>
    </tr>
    

    Now when you submit the form you will get correct values:

    public class HomeController: Controller
    {
        public ActionResult Index()
        {
            var model = new Enquiry();
            model.EnqProduct = ...
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Index(Enquiry model)
        {
            // the model.EnqProduct will be correctly populated here
            ...
        }
    }
    

    As far as the correct wire format that the default model binder expects for your input fields I would recommend you taking a look at the following article. It will allow you to more easily debug problems in the feature when some model is not properly populated. It suffice to look with FireBug and the name of the values being POSTed and you will immediately know whether they are OK or KO.

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

Sidebar

Related Questions

Was wondering if anyone had any smart approaches to creating dynamic vanity user urls
I'm creating a dynamic dropdown list on my page. When an option is selected
I'm creating a dynamic expression, which will order items in a list by some
I have used Android phonegap application for creating dynamic list with label and corresponding
I am creating dynamic menus and submenus in php.... Can't know where to start....
I'm creating dynamic templated XAML designs that I would like to convert to PNG
which method do you prefer for creating dynamic sql queries? formating or streaming? Is
I need to integrate the functionality of creating dynamic pages (like google sites) to
Im creating a dynamic MenuBar from xml file, and binding events to menu items
I'm creating an dynamic image, which creates headers on my page using PHPs GD-library.

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.