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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:16:10+00:00 2026-05-18T06:16:10+00:00

I currently have a bunch of methods in my controllers which take selected records

  • 0

I currently have a bunch of methods in my controllers which take selected records from table rows.

So I might have something like

var ids = [];
var prices = [];
var customers = [];

$selectedRow.each(function() {
    ids.push($(this).find('.id').text());
    prices.push($(this).find('.price').text());
    customers.push($(this).find('.customer').text());
});

$.post(....) // AJAX call to controller method

And in the controller I end up with

public ActionResult DoSomething(int[] ids, double[] prices, string[] customers) { ... }

which is just a bit messy to deal with using iterators.

What I’d really like is to have

Class Foo
{
    int id;
    double price;
    string customer;
}

and be able to receive

public ActionResult DoSomething(List<Foo> foos) { ... }

is this possible?

  • 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-18T06:16:11+00:00Added an answer on May 18, 2026 at 6:16 am

    A bit hacky but here’s an example:

    // query array: construct this as usual
    var array = [{ id: '1', name: 'name 1' }, { id: '2', name: 'name 2'}];
    
    // map the array into an array of DOM hidden fields
    var query = $.map(array, function (element, index) {
        return [$(document.createElement('input'))
                        .attr('type', 'hidden')
                        .attr('name', 'foos[' + index + '].id')
                        .val(element.id),
                    $(document.createElement('input'))
                        .attr('type', 'hidden')
                        .attr('name', 'foos[' + index + '].name')
                        .val(element.name)
                    ];
    });
    
    // construct a form
    var form = $(document.createElement('form'));
    $(query).appendTo(form);
    
    $.ajax({
        url: '<%: Url.Action("Test") %>',
        data: form.serialize(),
        dataType: 'json',
        success: function (result) {
            alert('success');
        }
    });
    

    This will successfully bind to a controller action of the form:

    public ActionResult Test(IEnumerable<Foo> foos) 
    {
        ...    
    }
    

    where Foo:

    public class Foo
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }
    

    Remark: All this is not necessary if you configure your controller action to accept JSON. In ASP.NET MVC 3 this is automatically included in the framework.

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

Sidebar

Related Questions

I currently have a bunch of SQLCHAR objects from a database query. The query
I currently have a bunch of repositories like so IMyRepository IAnotherRepository They all inherit
I currently have a table of concentrations, which are linked to a table of
I currently have something like this in ability.rb: if user.role? == staff can :update,
I'm currently refactoring a class which currently looks something like this: class SomeModel {
I have a bunch of models which currently extend ActiveRecord::Base. For all these models,
I'm building an app and currently I have a bunch of links that will
I currently have the following in select expert to select a bunch of fields:
Currently have a drop down menu that is activated on a hover (from display:none
Currently have password protection on my main and sub directories, however I'd like to

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.