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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:14:50+00:00 2026-05-23T11:14:50+00:00

I have a json array containing integers and objects. [1,2,3,{Name:russia,Value:6},{Name:usa,Value:8}] I also have the

  • 0

I have a json array containing integers and objects.

[1,2,3,{Name:"russia",Value:6},{Name:"usa",Value:"8"}]

I also have the following server-side class

class country {
  string Name;
  int Value;
}

How should I go about binding the json array to a server-side parameter ? I tried using a List<object> on server. It binds the integers fine but no country instances are created. Instead, primitive objects are created and added to the list.

Thanks.

  • 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-23T11:14:51+00:00Added an answer on May 23, 2026 at 11:14 am

    Okay, I solved it at last. I created a custom model binder derived from the default model binder to accomplish this. Here’s the code.

    public ActionResult Home(NonHomogeneousList input)
    
    [ModelBinder(typeof(CustomModelBinder))]
    class NonHomogeneousList : List<object>
    
    public class CustomModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
            {
                NonHomogeneousList model = (NonHomogeneousList)base.BindModel(controllerContext, bindingContext);
                if (model.Members != null)
                {
                    IModelBinder countryBinder = Binders.GetBinder(typeof(Country));
    
                // find out if the value provider has the required prefix
                bool hasPrefix = bindingContext.ValueProvider.ContainsPrefix(bindingContext.ModelName);
                string prefix = (hasPrefix) ? bindingContext.ModelName + "." : "";
    
                for (var i = 0; i < model.Count; i++)
                {
                    var member = model.Members[i];
                    if (member.GetType().Equals(typeof(object)))
                    {
                        var subKey =  CreateSubIndexName( prefix , i);
                        ModelBindingContext innerContext = new ModelBindingContext()
                        {
                            ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(Country)),
                            ModelName = subKey,
                            ModelState = bindingContext.ModelState,
                            PropertyFilter = bindingContext.PropertyFilter,
                            ValueProvider = bindingContext.ValueProvider,
                        };
                        var country = countryBinder.BindModel(controllerContext, innerContext);
                        model.Members[i] =  country;
                    }
                }
            }
            return model;
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several string each containing a JSON representation of an array of objects.
I have a single array json string containing data: [{Name:John,Age:22}, {Name:Jack,Age:56}, {Name:John,Age:82}, {Name:Jack,Age:95}] I
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have an array of json objects like so: [{a:b},{c:d},{e:f}] What is the best
My problem: I have an JSON Array containing arrays, which i render into the
I have JSON array created having code like user_images.push({'href' : value.href, 'title' : value.title
I have a class that I use to setup objects in an array. In
I have json array with a value that needs to be populated into an
I have a JSON string array of objects like this. [{id:4,rank:adm,title:title 1}, {id:2,rank:mod,title:title 2},
I have a JSON array coming in from the server with an array of

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.