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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:14:39+00:00 2026-06-12T19:14:39+00:00

I have a JavaScript variable which is basically an array of bounding boxes (called

  • 0

I have a JavaScript variable which is basically an array of bounding boxes (called bounds). Each array element is in the form of:

{
    XHigh: -71.00742992911023,
    XLow: -71.00670274612378,
    YHigh: 42.09467040703646,
    YLow: 42.09458047487587
}

And I’m trying to send it to an action method via POST:

$.ajax({
    url: '/Map/GetLocations',
    type: 'POST',
    data: { boxes: bounds },
    success: function(data) {
        // doing something with the result
    }
});

On the server, I consume the data into the action method as such:

[HttpPost]
public ActionResult GetLocations(IList<BoundingBox> boxes)
{
    // do something with boxes and return some json
}

With the DTO class defined as:

public class BoundingBox
{
    public decimal XHigh { get; set; }
    public decimal XLow { get; set; }
    public decimal YHigh { get; set; }
    public decimal YLow { get; set; }
}

Within the action method the boxes value does contain the correct number of elements that I sent in the POST. However, all of the decimal values are 0. I tried changing them to doubles in the DTO, still 0.0. I tried changing them to strings and they were empty.

Am I missing something in the model binding on how to populate these values? How can I send this array of objects to my action method?

  • 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-12T19:14:40+00:00Added an answer on June 12, 2026 at 7:14 pm

    I wrote a little helper for this problem because I got also stuck with some variations of your problem. I worked around these problems by sending a serialized version of my JS object to the server (using JSON.stringify()) and let MVC deserialize it on-the-fly.

    The first class I wrote is the JsonParameterAttribute. It instructs MVC to use my TypedJsonBinder when binding the decorated parameter.

    public class JsonParameterAttribute : CustomModelBinderAttribute
    {
        public override IModelBinder GetBinder()
        {
            return new TypedJsonBinder();
        }
    }
    

    The TypedJsonBinder takes the decorated parameter’s value as string and tries to deserialize it to the parameter’s type using the Json.NET library in my case. (You can use other deserialization technologies, of course.)

    public class TypedJsonBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            try
            {
                var json = (string) bindingContext.ValueProvider.GetValue(bindingContext.ModelName).ConvertTo(typeof (string));
    
                return JsonConvert.DeserializeObject(json, bindingContext.ModelType);
            }
            catch
            {
                return null;
            }
        }
    }
    

    You can then use the JsonParameterAttribute like this:

    public ActionResult GetLocations([JsonParameter] List<BoundingBox> boxes)
    {
        // ...
    }
    

    And don’t forget to serialize:

    $.ajax({
        url: '/Map/GetLocations',
        type: 'POST',
        data: { boxes: JSON.stringify(bounds) },
        success: function(data) {
            // doing something with the result
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have javascript variable obj which represents an element in the DOM and I
I have a javascript variable which looks like: data = [{ y: 55.11, color:
I have a JavaScript file which has a variable as such: var ads =
I have a JavaScript variable I grabbed from a form field and I am
I have a JavaScript variable which contains the name of a JavaScript function. This
I have a Javascript variable which I am setting a PHP variable to. function
I have a javascript variable which is referencing a complex object (it is a
i have a javascript variable which contains a string with new lines and spaces
I have a Javascript variable whatToRefresh which is defined in this way: var whatToRefresh
I have session key that is a JavaScript variable which I got from a

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.