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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:51:00+00:00 2026-05-26T12:51:00+00:00

I created my own simple shopping cart following the Music store mvc example. Problem

  • 0

I created my own simple shopping cart following the Music store mvc example. Problem is, my shop only allows one item addition at a time. But now I need a way to add multiple items at once to a cart and specify the quantity.

I was thinking about doing this: Model Binding to a List, but my Item model does not have a quantity property to hold the needed cart quantity.

public int ItemID { get; set; }

public string Barcode { get; set; }

public string Name { get; set; }

public string Description { get; set; }

public decimal Price { get; set; }

and my viewmodel:

public class ItemViewModel
{
    public int ItemID { get; set; }

    public string Barcode { get; set; }

    public string Name { get; set; }

    public string Description { get; set; }

    public decimal Price { get; set; }

    public int Quantity { get; set; }
}

public class ItemToCartViewModel
{
    public List<ItemViewModel> itemToCart { get; set; }
}

doesn’t seem to post properly in my post action (null or no values passed):

[HttpPost]
public ActionResult addtocart(ICollection<ItemViewModel> items)
{ ... }

Any ideas?

UPDATE:

@model IList<MyTGP.ViewModels.ItemViewModel>
@{
    ViewBag.Title = "Search for Items";
    int count = 0;
}
<h2>
    Search for Items</h2>
@Html.Partial("_SearchItemsPartial")

@using (Html.BeginForm("addtocart","Cart"))
{ 
if (String.IsNullOrEmpty(ViewBag.NoRecord)) {
<table>
    <tr>
        <th>
            Barcode
        </th>
        <th>
            Name
        </th>
        <th>
            Description
        </th>
        <th>
            Price
        </th>
        <th>
            Quantity
        </th>
    </tr>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Barcode)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Description)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Price)
            </td>
            <td>
                @Html.EditorFor(modelItem => item.Quantity)
            </td>
        </tr>
        count++;
    }
</table>
} else { @ViewBag.NoRecord }
<p>
    <input type="submit" value="add items to cart" />
</p>
}
  • 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-26T12:51:00+00:00Added an answer on May 26, 2026 at 12:51 pm

    I can’t comment yet so I’m posting here. Can you show us the view? The html is important.

    Update:
    Try like this (in the foreach loop)

    @Html.Hidden("["+count+"].ItemID",item.ItemID)
    @Html.Hidden("["+count+"].Barcode",item.Barcode)
    @Html.Hidden("["+count+"].Name",item.Name)
    @Html.Hidden("["+count+"].Description",item.Description)
    @Html.Hidden("["+count+"].Price",item.Price)
    

    Then where you display the quantity @Html.TextBox("["+count+"].Quantity",item.Quantity)

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

Sidebar

Related Questions

I've trouble with actionListener. I created own simple dialog, which has only two JButtons
I have a - maybe very simple - problem: I created my own library
I have created my own mvc pattern based on the codeigniter framework style. My
I created a simple WCF web service(following this tutorial: http://blogs.msdn.com/b/ericwhite/archive/2010/05/11/getting-started-building-a-wcf-web-service.aspx ), because I don't
I have created my own simple logger class which uses COM interop to redirect
Devise a simple algorithm which creates a file which contains nothing but its own
I created my own class but when I try to instantiate it I run
I created my own custom date picker consisting of an ASP TextBox, Button, and
I created my own behavior as follows: public class BoundaryExceptionHandlingBehavior : IInterceptionBehavior { public
I've created my own signup form and creating the user using the Membership class.

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.