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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:57:34+00:00 2026-05-28T19:57:34+00:00

I am trying to send some JSON data to my ASP.NET MVC3 controller action

  • 0

I am trying to send some JSON data to my ASP.NET MVC3 controller action method, but it won’t work no matter what I do.

Here is my ajax call (it uses the JSON.stringify method from the json2.js):

$.ajax({
        url: '/Home/GetData',
        type: "POST",
        dataType: "json",
        contentType: "application/json; charset=utf-8;",
        data: JSON.stringify(filters_data),
        success: function (data) {
            alert(data);
        }
    });

The Fiddler shows the request like this:

POST http://localhost:51492/Home/GetData HTTP/1.1
Host: localhost:51492
Connection: keep-alive
Content-Length: 171
Origin: http://localhost:51492
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko)     Chrome/16.0.912.75 Safari/535.7
Content-Type: application/json; charset=UTF-8;
Accept: application/json, text/javascript, */*; q=0.01
Referer: http://localhost:51492/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

{"Filters":[{"Field":3,"Operator":0,"Values":["30.01.2012.","30.01.2012."]},{"Field":2,"Operator":0,"Values":["-1"]},{"Field":0,"Operator":0,"Values":["some-string"]}]}

My c# code:

[HttpPost]
public string GetData(QueryFilters filters)
{
     return "Ho ho ho and a bottle of rum.";
}

[Serializable]
public enum Fields
{
        A,
        B,
        C,
        D
}

[Serializable]
public enum FilterOperator
{
    Is,
    Between,
    GreaterOrEqual,
}

[Serializable]
public class QueryFilter
{
    public Fields Field { get; set; }
    public FilterOperator Operator { get; set; }
    public List<string> Values { get; set; }
}

[Serializable]
public class QueryFilters
{
    public List<QueryFilter> Filters { get; set; }
}

I have added the following line to the Application_Start() method of global.asax.cs:

ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());

The breakpoint in the action method ‘GetData’ is hit, but the value of the Filters property is null. Any ideas?

Another note: I have tried passing a much simpler object: Person – properties string Name and int Age, with the same result – it appears as if the automated model binding isn’t working for me but I don’t know how to check it.

  • 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-28T19:57:35+00:00Added an answer on May 28, 2026 at 7:57 pm

    The problem is that your action argument is called filters and that inside your QueryFilters model you have a property called Filters which confuses the default model binder.

    So simply rename your action argument:

    [HttpPost]
    public ActionResult GetData(QueryFilters model)
    {
        return Json("Ho ho ho and a bottle of rum.");
    }
    

    Oh and notice that actions should return ActionResults not strings.

    Also remove the following line from your global.asax:

    ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
    

    ASP.NET MVC 3 already has this built-in.

    Or if you absolutely for some reason need to have your action argument called filters then you could also modify the JSON request you are sending to this:

    data: JSON.stringify({
        filters: { 
            Filters: [
                { "Field": 3, "Operator": 0, "Values": ["30.01.2012.", "30.01.2012."] },
                { "Field": 2, "Operator": 0, "Values": ["-1"] },
                { "Field": 0, "Operator": 0, "Values": ["some-string"] }
            ]
        }
    }),
    

    Now there’s no more ambiguity.

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

Sidebar

Related Questions

I am trying to send a model to ASP.NET MVC controller action, but for
I'm trying to send some data to PHP using HTTPService POST but for some
I'm trying to send some data via JQuery ajax to a grails controller Here's
I am trying to send some data from a LINQ query in C# to
I am currently trying to send some data from and Android application to a
I'm trying to use the PHP json_encode function to encode some JSON to send
I'm trying to make a call to a JSON ASP.NET web service with .NET.
I'm trying to send an associative array from PHP to Javascript. But, for some
I am trying to retrieve some data from a database using jQuery's $.getJSON method
Trying to send some email in my C# app. I am behind a proxy

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.