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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:01:43+00:00 2026-06-13T13:01:43+00:00

I have a MVC 4 web api application that receives json objects and uses

  • 0

I have a MVC 4 web api application that receives json objects and uses the standard model binding facility to bind them to my poco objects for easy use in my controller methods.

This all works great, when the json structures I am receiving map directly to my poco. for example I have a controller method

 public HttpResponseMessage Post(DeviceConfigurationDto deviceConfiguration)

and DeviceConfigurationDto is

public class DeviceConfigurationDto
    {
        public long Timestamp { get; set; }
        public string DeviceType { get; set; }
        public string AssetName { get; set; }
    }
}

and I post the following JSON

 {
        "Timestamp": 234234234,
        "DeviceType": "A555tom",
        "AssetName": "HV103"
    }

The built in model binding facility does a pretty good job of working with variations, like extra fields or fields missing and so forth. But if you push it to far. for example by posting the following json

    [
    {
        "Fields4": "asda",
        "Timestamp": 234234234,
        "DeviceType": "A555tom",
        "AssetName": "HV103"
    },
    {
        "Timestamp": 234234234,
        "DeviceType": "A555tom",
        "DedviceType": "A555tom",
        "AssetName": "HV103"
    }
]

It eventually falls over and I end up with the parameter into my method being null.

Is there a way for the model binding to work when the data is as expected, but then also provide me with the ability to get to the data that was a problem for the model binder, so that I can log the request that I am receiving that are not matching what I expected?

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-06-13T13:01:44+00:00Added an answer on June 13, 2026 at 1:01 pm

    One way to do this is to use custom ActionFilter. Since model binding happens before an action filter is executed, you can get your action argument(s) in your a custom action filter.

    For example:

    public class LogFailToModelBindArgActionFilterAttribute : System.Web.Http.Filters.ActionFilterAttribute
    {
        public override void OnActionExecuting(HttpActionContext context)
        {
            var deviceConfigurationArg = context.ActionArguments["deviceConfiguration"];
            if (deviceConfigurationArg == null) // fail to model bind data to argument ...
            {
                var jsonContent = context.Request.Content.ReadAsStringAsync().Result; // calling .Result here for sake of simplicity...
                Log(jsonContent);
            }
        }
    }
    

    Action:

        [LogFailToModelBindArgActionFilter]
        public HttpResponseMessage Post(DeviceConfigurationDto deviceConfiguration)
        {...}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC 4 application which uses the new ASP.NET Web API.
I have a .net 4 MVC Web Api application that I originally built in
I have a layered web application that I built with ASP.NET MVC 4, WebAPI
I have a ASP.NET MVC 4 application with Web API. It's working great. But
I was under the impression that model binding in the ASP.Net Web API was
All of my datamodels have field DateAdded. When the user (through MVC Web API)
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
My project consist of: MVC, WEB API solution. I have generated an ADO.NET entity
I have C# MVC web app that has some textboxes that in IE9 you
I have developed a MVC web application with ASP.NET MVC and im just wondering

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.