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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:39:33+00:00 2026-05-29T05:39:33+00:00

I am trying to loop these variables below (item_name, quantity and amount) @using (Html.BeginForm(PostToPaypal,

  • 0

I am trying to loop these variables below (item_name, quantity and amount)

@using (Html.BeginForm("PostToPaypal", "ShoppingCart"))
{

for (int i = 0; i < 10; i++)
{
    foreach (var item in Model.CartItems)
    {
   <input type="hidden" name="item_name" value="@item.Product.Title"/>
   <input type="hidden" name="quantity" value="@item.Count" />
   <input type="hidden" name="amount" value="@item.Product.Price"/>   
    }
}

    <input type="submit" name="btnsubmit" value="Pay with PayPal" />
}

I do not know how to merge these two for loops.
And i do not know how to use the “int i ..” in the “input type field”

Could somebody please explain to me (in code) how i can achieve this?

ShoppingCartController;

   public ActionResult PostToPaypal(string item_name, string quantity,string amount)
     {
        ESpiceHerbs.Models.PayPal paypal = new Models.PayPal();

        paypal.cmd = "_xclick";
        paypal.business = ConfigurationManager.AppSettings["BusinessAccountKey"];
        paypal.no_shipping = "1";
        bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandBox"]);
        if (useSandbox)
            ViewBag.actionURL = "https://www.sandbox.paypal.com/cgi-bin/webscr";
        else
            ViewBag.actionURL = "https://www.paypal.com/cgi-bin/webscr";

        paypal.cancel_return = ConfigurationManager.AppSettings["CancelURL"];
        paypal.@return = ConfigurationManager.AppSettings["ReturnURL"];//+"&PaymentId=1"; you can append your order Id here
        paypal.notify_url = ConfigurationManager.AppSettings["NotifyURL"]; // +"?PaymentId=1"; to maintain database logic 

        paypal.currency_code = ConfigurationManager.AppSettings["CurrencyCode"];

        paypal.item_name = item_name;
        paypal.quantity = quantity;
        paypal.amount = amount;
        return View(paypal);
    }

PayPal.Model

    public class PayPal
    {
    public string cmd { get; set; }
    public string business { get; set; }
    public string no_shipping { get; set; }
    public string @return { get; set; }
    public string cancel_return { get; set; }
    public string notify_url { get; set; }
    public string currency_code { get; set; }
    public string item_name { get; set; }
    public string quantity { get; set; }
    public string amount { get; set; }
}

And PostToPayPal.cshtml

    <form id="frm" action="@ViewBag.actionURL">
        @Html.HiddenFor(model => model.cmd)
        @Html.HiddenFor(model => model.business)
        @Html.HiddenFor(model => model.no_shipping)
        @Html.HiddenFor(model => model.@return)
        @Html.HiddenFor(model => model.cancel_return)
        @Html.HiddenFor(model => model.notify_url)
        @Html.HiddenFor(model => model.currency_code)
        @Html.HiddenFor(model => model.item_name)
        @Html.HiddenFor(model => model.quantity)
        @Html.HiddenFor(model => model.amount)
    </form>

I have referenced the PayPal method from http://www.arunrana.net/2012/01/paypal-integration-in-mvc3-and-razor.html

  • 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-29T05:39:34+00:00Added an answer on May 29, 2026 at 5:39 am

    I think what you might need is this:

    @using (Html.BeginForm("PostToPaypal", "ShoppingCart"))
    {
    
        for (int i=0; i<Model.CartItems.Count; i++)
        {
            @Html.HiddenFor(m => m.CartItems[i].Product.Title)
            @Html.HiddenFor(m => m.CartItems[i].Count)
            @Html.HiddenFor(m => m.CartItems[i].Product.Price) 
        }
    
    <input type="submit" name="btnsubmit" value="Pay with PayPal" />
    

    }

    And then on the PostToPaypalAction:

        [HttpPost]
        public ActionResult PostToPaypal(MODELTYPEHERE[] model)
        {
            //processing here
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the below code I'm trying to loop through each child node and append
I'm trying to define variables within a loop. I'll drop the code here and
I'm trying to do the right thing by not using global variables in my
I am trying to loop the below iteration, the code is below and i
I'm trying to loop through items of a checkbox list. If it's checked, I
I am trying to loop though my users database to show each username in
I am trying to loop from 100 to 0. How do I do this
I am trying to loop over a dictionary, specifically the request object's meta property.
I am trying to loop through a directory of text files and combine them
I'm trying to loop through the results from the Last.fm API but it's not

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.