Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options to format SendForm item list #450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fcsobel
Copy link

@fcsobel fcsobel commented Feb 16, 2014

Add SendForm options itemFormat & indexStart to allow list formatting.

Ex: Can be used to format POST for simple asp.net mvc model binding:

        simpleCart({
            checkout: {
                type: "SendForm",
                url: "/checkout",
                method: "POST",
                itemFormat: 'items[{index}].{name}',
                indexStart: 0
            }
        });

Results in post that will bind to list of items:
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/

  items[0].name
  items[0].quantity
  items[0].price
  items[0].options
  items[1].name
  items[1].quantity
  items[1].price
  items[1].options
  ...etc

Example c# checkout model

    public class CheckoutModel
    {
        public string Currency { get; set; }
        public decimal Tax { get; set; }
        public decimal TaxRate { get; set; }
        public int ItemCount { get; set; }
        public List<CartItem> Items { get; set; }
    }

    public class CartItem
    {   
        public string Name { get; set; }
        public int Quantity { get; set; }
        public decimal Price { get; set; }
        public string Options { get; set; }
    }

Add SendForm options to allow item formatting setting index start. 

Ex used for mvc model binder:
    type: "SendForm",
    itemFormat: 'items[{index}].{name}',
    indexStart: 0

Results in:
  items[0].name
  items[0].quantity
  items[0].price
  items[0].options
  items[1].name
  items[1].quantity
  items[1].price
  items[1].options
  ...etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant