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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:07:31+00:00 2026-06-06T00:07:31+00:00

Last night I tried to put together something that I have had working since

  • 0

Last night I tried to put together something that I have had working since MVC2.

Given the following class:

public class RouteSaveViewModel
{
    public string Title { get; set; }
    public string Comments { get; set; }
    public string DepartureDate { get; set; }
    public string ArrivalDate { get; set; }
    public List<int> LocationIds { get; set; }
}

…and the action below:

    [HttpPost]
    public ViewResult SaveRoute(RouteSaveViewModel route)
    {
        // yada yada
        return SomethingShiny();
    }

I would like to pass in the data using a $.ajax or $.post. The form is multi-step to collect data from the user and submit it. The code I use to build the location Ids up is this:

        var routeStopIds = [];
        $(".route-stop").each(function(){
            routeStopIds.push($(this).attr('data-id'));
        });

I have verified that there the ids I expect are in this array through in-browser dev tools and fiddler. Finally, to submit the data, I’m mapping out the object as I’ve done in previous MVC builds:

        $.ajax({
            type: 'post',
            url: postUrl,
            data: {
                Title: $("#route-title").val(),
                Comments: $("#route-description").val(),
                DepartureDate: depDate,
                ArrivalDate: arrDate,
                LocationIds: routeStopIds                    
            },
            dataType: 'JSON'
        });

What I’m seeing is that all data – except the LocationIds param is populated. I have also tried to submit just the routeStopIds array to a modified SaveRoute that only accepts a List<int> and that doesn’t appear to be working either. Either way, LocationIds is null, though there is a form-encoded value in the form parameters on the request.

{LocationIds%5b%5d=44&LocationIds%5b%5d=4&LocationIds%5b%5d=2}

…and yet the HttpValueCollection is just LocationIds[], an empty array.

So, am I missing something obvious? Maybe not-so-obvious? How do I get the array to be picked up by model binding?

  • 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-06-06T00:07:33+00:00Added an answer on June 6, 2026 at 12:07 am

    Remember that part where I said I had it working since MVC2? Yeah, that was here:
    Advanced Model Binding In that post I explicitly mentioned the following:

    Note: In order to make the results of the array compatible with the
    binding mechanism in ASP.NET MVC (as at MVC 2.0) we need to use the
    ‘traditional’ setting in $.ajax().

    Modifying the ajax call to include this setting was the fix. All is right as rain and soft woolen kittens. Or mittens or whatever.

            $.ajax({
                type: 'post',
                url: postUrl,
                traditional: true, // <----- here be kittens
                data: {
    
                    Title: $("#route-title").val(),
                    Comments: $("#route-description").val(),
                    DepartureDate: depDate,
                    ArrivalDate: arrDate,
                    LocationIds: routeStopIds 
                },
                dataType: 'JSON'
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This was working last night, but I must have accidentally changed something, because it
Last night I think I did something that hosed my rails development environment, and
I have a local cakephp 1.2 app which was working fine last night. Currently
I am new to clojure and I have tried to compile it last night
So I tried learning LaTeX last night, and I trying to get this template
Eclipse was running fine last night, but this morning I tried starting it up
Last night I had a script go a bit crazy and create a bunch
Update: Last night, I decided that this is just too much work to change
I've installed xCode 4 last night and tried to compile a software which should
I was working on my game last night in XCode and wanted to remove

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.