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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:27:27+00:00 2026-05-24T04:27:27+00:00

I am trying to submit all the items in a select list to an

  • 0

I am trying to submit all the items in a select list to an MVC 3 action method. Here is my Action method:

[HttpPost]
public ActionResult SaveList(int SettingID, List<SelectListItem> items)
{
    // blah...
}

and here is the simplified version of how I am trying to send the data:

var items = $("#listItems > option").map(function ()
{
    var arr = [];
    arr.push({ Value: $(this).val(), Text: $(this).text() });
    return arr;
}).get();

$.ajax({
    type: "POST",
    url: "/CompanyAdmin/SaveSettingList/",
    dataType: 'json',
    data: { items: items, SettingID: SettingID},
    success: function (msg)
    {
        alert(msg);
    }
});

The setting ID param gets populated correctly. And the List gets populated with the correct AMOUNT of items, but both the Text and Value properties come out as null.

Do I have to install one of the JSON plugins for jQuery to be able to submit an array of items?

EDIT 1:

Following Darin Dimitrov’s advice I used the stringify method and sent both the SettingID and list of options as JSON.

At first this was not hitting my Action method, so I changed the method to this:

public ActionResult SaveList(SaveSettingListModel json)
{}

with the param being defined like so: (to match the JSON)

public class SaveSettingListModel
{
    public int SettingID { get; set; }
    public List<SelectListItem> items { get; set; }
}

This now fires the correct method. However, the contents of json on the server side are SettingID = 0 (when I verified that it is 2 on the client side), and items = null.

  • 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-24T04:27:28+00:00Added an answer on May 24, 2026 at 4:27 am

    Try posting them as JSON.

    Start by defining a view model:

    public class MyViewModel
    {
        public int SettingID { get; set; }
        public List<SelectListItem> Items { get; set; }
    }
    

    then modify your controller action to take this view model as argument:

    [HttpPost]
    public ActionResult SaveList(MyViewModel model)
    {
        // blah...
    }
    

    and finally in your script:

    var items = $('#listItems > option').map(function ()
    {
        var arr = [];
        arr.push({ value: $(this).val(), text: $(this).text() });
        return arr;
    }).get();
    
    $.ajax({
        type: 'POST',
        url: '/CompanyAdmin/SaveSettingList/', // <-- use an URL Helper to generate this url instead of hardcoding it or you will cry when you deploy your application into a virtual directory
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({ 
            items: items, 
            settingID: SettingID 
        }),
        success: function (msg) {
            alert(msg);
        }
    });
    

    And if you want to use the JSON.stringify method in legacy browsers in which it is not natively supported make sure you include the json2.js script.

    All this being said I see where you are going with this controller action and with this AJAX request and I must say that I wouldn’t do it this way (send the options in the request). I mean in order to render this view you fetched this list from somewhere? Presumably a datastore? So instead of fighting with the HTML <form> (which sends only the selected value of a dropdownlist to the server when submitted) why don’t you simply use this very same data store in your SaveList action in order to fetch those very same options? This will avoid you round-tripping them and save bandwidth. Don’t worry databases are fast. And if they are not in your case simply cache the results of expensive queries.

    Completely ignore my previous remark if those options are subject to change on the client side and you want to fetch the new values.

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

Sidebar

Related Questions

I am trying to submit a form with method GET and action index.php?id=3. The
I'm trying to make a list of items, where all these items can be
I've been trying to submit a form with the FormPanel using the Action class
I have a form within an ASP.NET MVC application and I'm trying to submit
I am probably going about this all wrong, but here's what I'm trying to
Im trying to submit a specific form programatically, but I allways get the initial
I'm trying to submit a form with javascript. Firefox works fine but IE complains
Well I am trying to submit a form by pressing enter but not displaying
i'm trying to submit my Ajax form using jQuery. However calling the submit() function
I'm trying to submit a few forms through a Python script, I'm using the

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.