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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:24:55+00:00 2026-06-14T09:24:55+00:00

I have a partial view with a view model that has a collection of

  • 0

I have a partial view with a view model that has a collection of sellers. I loop over all of the sellers to render the list. Here is the view model:

public class SellersPartialViewModel
{
    public IList<OrderViewModel> Sellers { get; set; }
}

In the partial view I’m using Html.BeginCollectionItem(“Sellers”) when I loop through the collection and here is my code for the partial (FYI I’ve stripped away a lot of useless code that doesn’t need to be seen):

<div id="sellers-list">
    @{
        var i = 0;
        while (i < Model.Sellers.Count) { 
            var seller = Model.Sellers[i];

                using (Ajax.BeginForm(MVC.Video.PurchaseShares(), purchaseSharesAjaxOptions, new { @class = "seller-form", id = "seller-form-" + i })) {
                    @using(Html.BeginCollectionItem("Sellers")) {
                        @Html.TextBoxFor(m => seller.Qty, new { @class = "buyer-qty" })
                        @Html.ValidationMessageFor(m => seller.Qty)

                       <input class="buyer-qty-submit" name="Qty" type="hidden" value="" />
                       <button type="submit">Buy</button>
                    }
                }
            }

            i++;
        }
    }
</div>

This works fine for rendering the partial and getting the client-side validation working
however I want each seller to have the inputs named qty and orderId for a controller action called PurchaseShares(int orderId, int qty).

The only problem is the form is being submitted with the odd GUID like Sellers[5b5fd3f2-12e0-4e72-b289-50a69aa06158].seller.Qty which I understand is correct for submitting collections but I don’t need to do that.

Right now I have some Javascript that is updating the class="buyer-qty" with whatever they select and it works fine but there has got to be a better way of doing this, no?

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-06-14T09:24:56+00:00Added an answer on June 14, 2026 at 9:24 am

    Why are you using the Html.BeginCollectionItem helper if you don’t want to submit collections?

    You could have a partial representing your Order collection item (_Order.cshtml):

    @model OrderViewModel
    
    @Html.TextBoxFor(m => m.Qty, new { @class = "buyer-qty" })
    @Html.ValidationMessageFor(m => m.Qty)
    

    And in your main view simply loop through your collection property and render the partial for each element:

    @model SellersPartialViewModel
    
    <div id="sellers-list">
        @foreach (var seller in Model.Sellers)
        {
            using (Ajax.BeginForm(MVC.Video.PurchaseShares(), purchaseSharesAjaxOptions, new { @class = "seller-form" }))
            {
                @Html.Partial("_Order", seller)
                <button type="submit">Buy</button>
            }
        }
    </div>
    

    Now your controller action you are submitting to could directly work with the corresponding view model:

    [HttpPost]
    public ActionResult PurchaseShares(OrderViewModel order)
    {
        ...
    }
    

    because:

    [HttpPost]
    public ActionResult PurchaseShares(int orderId, int qty)
    {
        ...
    }
    

    kinda looks uglier to me but it would also work if you prefer it.

    Also please notice that I have deliberately removed the Qty hidden field shown in your code as it would conflict with the input element with the same name. Also don’t forget to include an input field for the orderId argument that your controller action is expecting or when you submit it could bomb. Also you could send it as part of the routeValues argument of the Ajax.BeginForm helper if you don’t want to include it as an input field.

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

Sidebar

Related Questions

if i have created a view model and have a partial form that is
in a partial view I have the following: <%Html.RenderAction(MVC.User.GetComments(Model.UserGroupName)); %> can I render a
I have a partial view that has something like this <%= Html.DropDownListFor(m => m.SelectedProductName,
I have a partial view that has textfields in it and is bound to
I have a view that has some jQuery to load a partial view (via
I have a _layout page which has a login box (partial view) and that
I have a strong typed view model and a MetaData partial class which has
I have a jquery modal dialog that displays a partial view. The partial view
I have a partial view that I want to basically take care of itself
I have a partial view that is shared between two controllers and I'm trying

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.