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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:17:18+00:00 2026-06-01T16:17:18+00:00

So it seems like several people (like here and here ) have had issues

  • 0

So it seems like several people (like here and here) have had issues with MVC4 model binding for ApiControllers, but none of them seem to quite address the issue I’m seeing.

All I’d really like to do is change the array binding behavior for lists of integers. So say I had a request type like this:

public class MyRequestModel
{
    public List<long> ListOfIntegers { get; set; }

    ...
}

And an API GET method like this:

public ResultsResponseModel Get(MyRequestModel request)
{
    // use request.ListOfIntegers meaningfully

    ...

    return response;
}

I basically want to be able to say /api/results/?listOfIntegers=1+2+3+4+5 and have that resolve to the List<long> property.

I’ve tried my usual model binding tricks, but as with most of the Web API in MVC4 it appears to have a totally separate path for model binding.

The furthest I’ve gotten is using a System.Web.Http.ModelBinding.ModelBinder attribute on MyRequestModel, and creating a model binder that “implemented” System.Web.Http.ModelBinding.IModelBinder. That consistently yields an object reference exception with stack traces that never touch my code.

Anyone hit this? Have thoughts on what to try next?

UPDATE: Here’s a stack trace that I’ve captured in my custom ExceptionFilterAttribute:

Object reference not set to an instance of an object.
    at System.Web.Http.ModelBinding.DefaultActionValueBinder.BindParameterValue(HttpActionContext actionContext, HttpParameterBinding parameterBinding)
    at System.Web.Http.ModelBinding.DefaultActionValueBinder.<>c__DisplayClass1.BindValuesAsync>b__0(RequestContentReadKind contentReadKind)
    at System.Threading.Tasks.TaskHelpersExtensions.<>c__DisplayClass38.<ToAsyncVoidTask>b__37()
    at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
  • 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-01T16:17:20+00:00Added an answer on June 1, 2026 at 4:17 pm

    If you’re talking ApiControllers, then you’re trying to model bind in Web API and now MVC
    Here’s a sample model binder

      public class MyRequestModelBinderProvider : ModelBinderProvider
        {
            MyRequestModelBinder binder = new MyRequestModelBinder();
            public IdeaModelBinderProvider()
            {          
            }
    
            public override IModelBinder GetBinder(HttpActionContext actionContext, ModelBindingContext bindingContext)
            {
                if (bindingContext.ModelType == typeof(MyRequestModel))
                {
                    return binder;
                }
    
                return null;
            }
        } 
    

    Here’s an example of registering a custom model binder provider

     IEnumerable<object> modelBinderProviderServices = GlobalConfiguration.Configuration.ServiceResolver.GetServices(typeof(ModelBinderProvider));
     List<Object> services = new List<object>(modelBinderProviderServices);
     services.Add(new MyRequestModelBinderProvider());
     GlobalConfiguration.Configuration.ServiceResolver.SetServices(typeof(ModelBinderProvider), services.ToArray());
    

    Now in your custom model binder you use the contexts to access the querystring values

      public class MyRequestModelBinder :  IModelBinder
        {
            public MyRequestModelBinder()
            {
    
            }
    
            public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
            {
                MyRequestModel yourModel; 
                //use contexts to access query string values
                //create / update your model properties
    
                bindingContext.Model = yourModel;  
                //return true || false if binding is successful
            }
    

    Make sure your using the classes and interfaces for WebAPI and not MVC. Some of the names are the same, but different namespaces and dlls

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

Sidebar

Related Questions

This question have been asked by several people but my problem seems to be
This seems like such a simple question. I have several Edit boxes on my
I've recently seen several people doing things like this here on Stackoverflow: class A:
I've recently seen several people doing things like this here on Stackoverflow: class A:
From discussions I've had about language design, it seems like a lot of people
Seems like a lot of people have problems getting oAuth to work with Photobucket
Seems like this should be obvious, but how do I send arrow key presses
Seems like this should be simple, but powershell is winning another battle with me.
Seems like just yesterday I had this same problem with Play! v1. After trying
This seems like it should be obvious but I can't figure it out. Suppose

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.