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

  • Home
  • SEARCH
  • 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 9134469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:39:55+00:00 2026-06-17T08:39:55+00:00

I have built a ‘buy products’ page dynamically by building it up for each

  • 0

I have built a ‘buy products’ page dynamically by building it up for each product. Each product has an ‘Add to Basket’ button, which are differentiated for each product by having the pID as the buttons name attribute. I now want to get the value of the name attribute within my controller on postback. Not sure how to do this:

View:

@foreach (Ecommerce.Models.HomeModels.Product product in Model)
{
    using (Html.BeginForm())
    {
        @Html.Label(product.Name);
        <br />
        @Html.Label(product.Description);
        <br />
        @Html.Label(product.UnitPrice.ToString());
        <p></p>


        <input name="@product.ID" type="submit" value="Add to Basket" /> 
    }
}

Controller:

[HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult BuyProducts(string button)
        {

        }
  • 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-17T08:39:56+00:00Added an answer on June 17, 2026 at 8:39 am

    If you don’t have multiple submit buttons inside a form then there is no need to know on the server side what was the name of the clicked submit button. There are other ways to send back your Id to the server:

    Why don’t you just generate a hidden field inside your form to hold and post the data?

    @foreach (Ecommerce.Models.HomeModels.Product product in Model)
    {
        using (Html.BeginForm())
        {
            <input type="hidden" name="productId" value="@product.ID" />
            <input  type="submit" value="Add to Basket" /> 
        }
    }
    

    Then you can get the value of the hidden field in your controller:

    public ActionResult BuyProducts(string productId)
    {
        //..
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a voucher website, where each voucher has a countdown timer. When
I have built a database on multiple tables. One of these tables has a
I have built a Twitter client that's only one page: index.html. When being used,
I have built a form which has a VBox inside of a VBox .
I have built a screen where an administrator can add and edit users. I'm
I have built the following page a while ago: http://www.cnplumbingandheating.co.uk/#page=about However, the ID card
I have built a magento template module that produces a list of products for
I have built a basic script to do an elementary math add 1 on
I have built an Android chat application. It has a TCP server which is
I have built a dom object Engine that has private/public fields/methods that I have

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.