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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:32:02+00:00 2026-06-02T05:32:02+00:00

I am making this ajax call: $.ajax({ url: /test/whatever, type: ‘post’, contentType: ‘application/json’ data:

  • 0

I am making this ajax call:

   $.ajax({
        url: "/test/whatever",
        type: 'post',
        contentType: 'application/json'
        data: {"fieldone":'test',"fieldtwo":'',"fieldthree":null,"fieldfour":'test'}
    });

in the controller I have:

    [HttpPost]
    public string Whatever(MyModel object)
    {
        //fieldone, fieldtwo and fieldthree are all type string  
        //at this point:
        // object.fieldone contains the string 'test'
        // object.fieldtwo is NULL, but WHY?! and how can I have it correctly deserialize to blank string
        // object.fieldthree is correctly null, which is fine
        // I have no fieldfour in my object, so it is ignored, that makes sense.
        // object.newfield is correctly null, because I didn't pass a value for it in my JS
    }

So, does anyone know why blank strings are turning into nulls in this case?
I found this post which talks about a bug in javascriptserializer for nullable properties:

http://juristr.com/blog/2012/02/aspnet-mvc3-doesnt-deserialize-nullable/

But my case is even simpler than that, I just want to deseralize and object that contains descriptive fields, some of which might be blank strings.

I need to tell the difference between blank strings and nulls so that I can throw an exception if I get any nulls (my client js code isn’t in sync with the c# object ususally when this happens and I want to know about it).

Any MVC experts out there who can shed light on this for me?

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-02T05:32:04+00:00Added an answer on June 2, 2026 at 5:32 am

    I think the problem is that the default behavior for the ModelBinder is to convert empty fields to the default value of the type in your model (MyClass) so sending an empty string in those field would translate to

     ... = default(string); 
    

    which would give you null.

    To change this behavior I think you need to create your own ModelBinder for that class and set those fields to empty string if they come in the request but they are empty

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

Sidebar

Related Questions

I have this ajax call at the moment: $.ajax({ url: misc/sendPM.php, type: POST, data:
When making an ajax call, when contentType is set to application/json instead of the
am making an ajax call to retrive json data i then store the retrived
I am making ajax call like this $(document).ready(function() { var abc = new Array();
I am including a jsp fragment by making an ajax call. Now this jsp
I am using this jQuery.ajax: var url = http://client.my_url.com/test_get_account_data.php; jQuery.ajax({ type: GET, url: url,
Trying to find out why this jQuery JS isn't making ajax call though it
I'm making a call to another ajax page, the call posts a json object.
I have some JavaScript that is making an Ajax call to a relative url
I am making an ajax call using the following code. $.ajax( { url: '/BuildingCompany/EditAjax/'

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.