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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:47:27+00:00 2026-06-14T23:47:27+00:00

hi i am trying to insert multiple records at same time from single form

  • 0

hi i am trying to insert multiple records at same time from single form following are my models and views

My Models

public class Invoice
{
    public int InvoiceID { get; set; }
    public string InvoiceNo { get; set; }
    public DateTime InvoiceDate { get; set; }
    public bool Posted { get; set; }

    public virtual List<InvoiceDetail> InvoiceDetails { get; set; }
}


public class InvoiceDetail
    {
        public int InvoiceDetailID { get; set; }

        public int InvoiceID { get; set; }
        public Invoice Invoice { get; set; }

        public int ItemID { get; set; }
        public virtual Item Item { get; set; }

        public double Price { get; set; }
        public double Quantity { get; set; }
    }

public class Item
    {
        public int ItemID { get; set; }
        public string Description { get; set; }        
    }

In View

 @model IList<MultiInsert.Models.InvoiceDetail>
@{
    ViewBag.Title = "Create";
}
<h2>
    Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>InvoiceDetail</legend>
        @for (int i = 0; i < 2; i++)
        {        
            <div class="editor-label">
                @Html.LabelFor(model => model[i].ItemID, "Item")
            </div>
            <div class="editor-field">
                @{string itemid = "[" + i + "].ItemID";
                    @Html.DropDownList("ItemID", String.Empty)
                    @Html.ValidationMessageFor(model => model[i].ItemID)
                }
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model[i].Price)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model[i].Price)
                @Html.ValidationMessageFor(model => model[i].Price)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model[i].Quantity)
            </div>
            <div class="editor-field">
                @Html.EditorFor(model => model[i].Quantity)
                @Html.ValidationMessageFor(model => model[i].Quantity)
            </div>
        }
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

the problem is that my code generates following html which is as follows

<div class="editor-field">
<select id="ItemID" name="ItemID"><option value=""></option>
<option value="1">SALT</option>
<option value="2">RED CHILI</option>
</select><span class="field-validation-valid" data-valmsg-for="[0].ItemID" data-valmsg-replace="true"></span>            </div>
            <div class="editor-label">
                <label for="">Price</label>
            </div>
            <div class="editor-field">
                <input class="text-box single-line" data-val="true" data-val-number="The field Price must be a number." data-val-required="The Price field is required." name="[0].Price" type="text" value="" />
                <span class="field-validation-valid" data-valmsg-for="[0].Price" data-valmsg-replace="true"></span>
            </div>
            <div class="editor-label">
                <label for="">Quantity</label>
            </div>
            <div class="editor-field">
                <input class="text-box single-line" data-val="true" data-val-number="The field Quantity must be a number." data-val-required="The Quantity field is required." name="[0].Quantity" type="text" value="" />
                <span class="field-validation-valid" data-valmsg-for="[0].Quantity" data-valmsg-replace="true"></span>
            </div>

while it should generate something like

<select id="[0].ItemID" name="[1].ItemID"><option value=""></option>

any suggestions please

  • 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-14T23:47:29+00:00Added an answer on June 14, 2026 at 11:47 pm

    just use dropdownlistfor rather than simple dropdownlist.

    @Html.DropDownListFor(model => model[i].ItemID, (SelectList)ViewBag.ItemID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert multiple values to the same field using a single
I am trying to copy multiple records using one query using insert select from.
I got the following issue while trying to insert multiple entries into a MySQL
I am trying to make a query that will insert multiple values from my
I am trying to insert multiple records into a table where each record has
I am trying to insert multiple records into SQL database. SQL table contains smalldatetime
Need to load data from a single file with a 100,000+ records into multiple
Need to load data from a single file with a 100,000+ records into multiple
I'm trying to insert multiple rows into MySql with only one INSERT INTO statement
I am completely new in MySQL and trying to insert multiple rows in MySQL

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.