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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:33:50+00:00 2026-05-10T20:33:50+00:00

I am creating a small app to teach myself ASP.NET MVC and JQuery, and

  • 0

I am creating a small app to teach myself ASP.NET MVC and JQuery, and one of the pages is a list of items in which some can be selected. Then I would like to press a button and send a List (or something equivalent) to my controller containing the ids of the items that were selected, using JQuery’s Post function.

I managed to get an array with the ids of the elements that were selected, and now I want to post that. One way I could do this is to have a dummy form in my page, with a hidden value, and then set the hidden value with the selected items, and post that form; this looks crufty, though.

Is there a cleaner way to achieve this, by sending the array directly to the controller? I’ve tried a few different things but it looks like the controller can’t map the data it’s receiving. Here’s the code so far:

function generateList(selectedValues) {    var s = {       values: selectedValues //selectedValues is an array of string    };    $.post('/Home/GenerateList', $.toJSON(s), function() { alert('back') }, 'json'); } 

And then my Controller looks like this

public ActionResult GenerateList(List<string> values) {     //do something } 

All I managed to get is a ‘null’ in the controller parameter…

Any tips?

  • 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. 2026-05-10T20:33:51+00:00Added an answer on May 10, 2026 at 8:33 pm

    I modified my response to include the code for a test app I did.

    Update: I have updated the jQuery to set the ‘traditional’ setting to true so this will work again (per @DustinDavis’ answer).

    First the javascript:

    function test() {     var stringArray = new Array();     stringArray[0] = "item1";     stringArray[1] = "item2";     stringArray[2] = "item3";     var postData = { values: stringArray };          $.ajax({         type: "POST",         url: "/Home/SaveList",         data: postData,         success: function(data){             alert(data.Result);         },         dataType: "json",         traditional: true     }); } 

    And here’s the code in my controller class:

    public JsonResult SaveList(List<String> values) {     return Json(new { Result = String.Format("Fist item in list: '{0}'", values[0]) }); } 

    When I call that javascript function, I get an alert saying "First item in list: ‘item1’".

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

Sidebar

Related Questions

I'm creating a small app in ASP.NET MVC that generates ics (iCal) files based
I'm creating a small code plugin which allows you to do some things with
I am creating a small console app that needs a progress bar. Something like...
I am creating a small silverlight widget which pronounces a word and highlights each
I am creating a small modal form that is used in Winforms application. It
I am creating a small application that will be deployed on Window. The database
I'm creating a small application on an embedded device that has a boa web
I'm thinking of creating a small offline blog editor for personal use and I
I am planning on creating a small website for my personal book collection. 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.