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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:57:59+00:00 2026-06-13T05:57:59+00:00

I want to pass a JSON data structure to an MVC (3) Controller, have

  • 0

I want to pass a JSON data structure to an MVC (3) Controller, have the JSON object be translated into a C# object, with all properties bound. One of the properties is a simple Type. That’s basic model binding, right?

Here are my models:

public class Person
{
    public string Name { get; set; }
    public JobTitle JobTitle { get; set; }
}

public class JobTitle
{
    public string Title { get; set; }
    public bool IsSenior { get; set; }
}

Here is my Index.cshtml page (which makes an AJAX request, passing in a JSON object which matches the strcture of the “Person” class):

<div id="myDiv" style="border:1px solid #F00"></div>
<script type="text/javascript">
var person = { 
        Name: "Bob Smith",
        JobTitle: { 
            Title: "Developer",
            IsSenior: true
        } 
    };

$.ajax({
    url: "@Url.Action("ShowPerson", "Home")",
    data: $.param(person),
    success: function (response){
        $("#myDiv").html(response);
    },
    error: function (xhr) {
        $("#myDiv").html("<h1>FAIL</h1><p>" + xhr.statusText + "</p>");
    }
});
</script>

And my HomeController looks like this:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult ShowPerson(Person person)
    {
        return View(person);
    }
}

Ignore the “ShowPerson.cshtml” file for now because the problem occurs before that is ever needed.

In the HomeController.ShowPerson action, the “person.Name” property is correctly bound and the “person.JobTitle” object (containing “Title” and “IsSenior” properties) is instantiated but still has the default values of “Title = null” and “IsSenior = false”.

I’m sure I have done nested model binding without problem in the past. What am I missing? Can anybody shed any light on why model binding only seems to work one level deep?

I’ve searched SO, and it seems everybody else is having binding problems when sending data from forms, so maybe I’m missing something in my $.ajax() request?

  • 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-13T05:58:00+00:00Added an answer on June 13, 2026 at 5:58 am

    ok, there are couple of changes you need to do,

    • Set dataType as json
    • Set the contentType as application/json; charset=utf-8.
    • Use JSON.stringify()

    below is the modified code. (tested)

    var person = { 
        Name: "Bob Smith",
        JobTitle: { 
            Title: "Developer",
            IsSenior: true
        } 
    };
    
    var jsonData = JSON.stringify(person);
    
    $.ajax({
      url: "@Url.Action("ShowPerson", "Home")",
      data: jsonData,
      dataType: 'json',
      type: 'POST',
      contentType: "application/json; charset=utf-8",
    
      success: function (response){
        $("#myDiv").html(response);
      },
      error: function (xhr) {
        $("#myDiv").html("<h1>FAIL</h1><p>" + xhr.statusText + "</p>");
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following json data which I want to pass it to server using
I Have two problem in this Case : I want to pass a JSON
I have following code and i want to pass additional parameter in JSON.getJSONfromURL() method
Haskell beginner here. I want to pass a type parameter with JSON, and have
I want to pass a custom made vector object containing data from background service
I have asp.net mvc application. i want to configure the object in jquery and
Hi all i am using json to pass data in wcf service. Below is
I have a google map which I am getting json data from. I want
I want to pass JavaScript objects (JSON and function objects) into my ActiveX control.
i have this json data and i want to get length of this json

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.