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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:34:37+00:00 2026-05-12T19:34:37+00:00

I have the following in my view: <%using (Html.BeginForm()) {%> <% foreach (var item

  • 0

I have the following in my view:

<%using (Html.BeginForm()) {%>
<% foreach (var item in Model.Cart) { %>
    <div>
        <%= Html.TextBox("Cart.Quantity", item.Quantity, new { maxlength = "2" })%>
        <%= Html.Hidden("Cart.ItemID", item.ItemID)%>
    </div>
<% } %>
<input name="update" type="image" src="image.gif" />

I then have this code in my controller:

    public ActionResult Index()
    {
        CartViewData cartViewData = new CartViewData();
        IList<Item> items = ItemManager.GetItems();

        cartViewData.Cart = items;
        return View("Index", cartViewData);
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Index(CartViewData cartViewData)
    {
        // cartviewData is null
    }

Is there a way to grab the List on the postback to see if the values in the textboxes have changed?

Thanks

Below is a simplified example since it was requested:

<% for (int i = 0; i < Model.Cart.Count; i++ ) { %>
    <a href="javascript:void(0);" onclick="removeItem(<%= Model.Cart[i].ShoppingCartItemID %>);">Remove</a>
<% } %>

Hope this helps.

  • 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-12T19:34:38+00:00Added an answer on May 12, 2026 at 7:34 pm

    This simplest way is to do this – name each cart item control with this format:

    <input type="text" name="Items[0].Quantity" />
    

    Where the 0 corresponds to the index of the item in the items collection. Next, move the items collection to a property on the cart, so that you model looks something like this:

    class CartViewData 
    {
        public CartViewData()
        {
            this.Items = new List<Item>();
        }
    
        public IList<Item> Items { get; private set; }
    
        class Item
        {
           public int Quantity { get; set; }
        }
    }
    

    Then the DefaultModelBinder will bind the values to the model.

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

Sidebar

Related Questions

In my view I have the following code: @using (Html.BeginForm()) { @Html.TextBox(Date2, Model.Date2) <br/>
In an MVC3 app, i have the following View: @using (Html.BeginForm(Index, Search, new {query
I have the following code on a view: @using (Html.BeginForm()) { <div class=select-box form>
I have the following view: <h2> Contract</h2> @Using Html.BeginForm() @Html.ValidationSummary(False) @<fieldset> <legend>Hire Contract</legend> <div
I have the following in my Razor view: @using (Html.BeginForm(Edit, MyController, FormMethod.Post)) { <div
So I have the following code: @model Project.Models.ViewModels.SomeViewModel @using (Html.BeginForm(SomeAction, SomeController, new { id
I have the following form: <li> <% using (Html.BeginForm(TestMethod, MyController, FormMethod.Post, new {id =
I have the following View code: @using (Html.BeginForm(Login, Press, FormMethod.Post)) { <fieldset> <legend>User Registration</legend>
I'm new to MVC 3 and I have the following views: Index: @using (Html.BeginForm())
I have the following code in a MVC view: <% using (Html.BeginForm()) { %>

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.