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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:20:06+00:00 2026-05-11T21:20:06+00:00

If youa are serializing a form using something like jQuery, it will often map

  • 0

If youa are serializing a form using something like jQuery, it will often map the JSON keys and values to the properties of a object on the Controller Action you are posting to. So:

jQuery:

function PostForm() {
    $.ajax({
        url: "/Home/TestMVC",
        type: "POST",
        dataType: "application/JSON",
        data:  $('#form').serialize(),
        complete: callFunction
        }
    });

Presuming main details contains elements which will have the name of the parameter as a key they should map to the object directly:

Action:

public void TestMVC(MyObject obj)
{
//Obj should now contain the data from the serialised form
}

POST:

Name: "Bob"
Age: "999"
Sex: "Unknown"

Does anyone know how this works? It’s breaking every time I pass the form and any additional data to the controller.

I would like to send the contents of the data as well as a QueryString which could contain any number and types of key/value pairs to the controller. I can extract these key/value pairs on the server since I cannot create an object for them on the method signature. However, this fails to work as intended.

jQuery:

function PostForm() {

    $.ajax({
        url: "/Home/TestMVC",
        type: "POST",
        dataType: "application/JSON",
        data: 
        { 
           Obj: $('#form').serialize(),
           TheWeirdQueryString: $('.additionalParams').serialize(),
        }
    });
};

Action:

public void TestMVC(MyObject obj, String TheWeirdQueryString)
{
//Obj now does NOT contain the element, it is NULL. Whereas TheWeirdQueryString works fine. 
}

Post:

Obj: name=bob&age=999&sex="unknown"
TheWeirdQueryString: param1=1&param2=2

I think this is because I have actually created a JSON object as the Data and set the properties to the name of the object.

There is a difference in the POST values which appear in Firebug. When I post the object alone, the POST values are all the keys of the object/form with their corresponding values. In the second example there are two simple properties, The name I gave them, each containing a QueryString (Foo=1&Bar=2) and MVC cannot map a QueryString to the members of an object (or so it would appear).

Is there anyway at all to get to work like it does in the first instance, but also to send extra data to a 2nd argument on the Action? I am guessing it’s to add an extra property to all the existing ones created when jquery does the serialisation of the form.

The POST I actually want is:

Name: "Bob"
Age: "999"
Sex: "Unknown"
TheWeirdQueryString: param1=1&param2=2
  • 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-11T21:20:06+00:00Added an answer on May 11, 2026 at 9:20 pm

    dataType parameter in $.ajax method is the type of response (the type of data that you’re expecting back from the server), not request. Try this instead:

    function PostForm() {
        $.ajax({
            url: "/Home/TestMVC",
            type: "POST",
            dataType: "application/JSON",
            data: $('#form').serialize() + "&" + $('.additionalParams').serialize()
        });
    };
    

    or:

    function PostForm() {
        $.ajax({
            url: "/Home/TestMVC" + "?" + $('.additionalParams').serialize(),
            type: "POST",
            dataType: "application/JSON",
            data: $('#form').serialize()
        });
    };
    

    UPDATED:

    Try this:

    Controller:

    public void TestMVC(MyObject obj, String[] TheWeirdQueryString)
    {
    }
    

    Client:

    function PostForm() {
        $.ajax({
            url: "/Home/TestMVC",
            type: "POST",
            dataType: "application/JSON",
            data: $('#form').serialize() + "&" + $('.additionalParams').serialize()
        });
    };
    

    but on client side your additional params must be in the following format:

    TheWeirdQueryString[0]=param1&TheWeirdQueryString[1]=param2&...&TheWeirdQueryString[n]=paramN
    

    so $(‘.additionalParams’) elements must have “id” and/or “name” attributes like: TheWeirdQueryString[1], TheWeirdQueryString[2] … TheWeirdQueryString[N]

    Hope this helps

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

Sidebar

Ask A Question

Stats

  • Questions 154k
  • Answers 154k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A checksum comparison will most likely be slower than a… May 12, 2026 at 10:35 am
  • Editorial Team
    Editorial Team added an answer That's a pair of ternary operations. $transactionID = (isset($authNetCodes[4])) ?… May 12, 2026 at 10:35 am
  • Editorial Team
    Editorial Team added an answer Yes, the C# compiler itself is a prime example, csc.exe.… May 12, 2026 at 10:35 am

Related Questions

I am programming a control to allow the users of our intranet to upload
I would to know if there is a tool in C++ that gives you
What are the C++ rules for calling the base class constructor from a derived
Is there a tool which tells you (or gives you a hint) why a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.