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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:41:03+00:00 2026-05-24T09:41:03+00:00

I think I’ve found a bug in ASP.NET MVC controller’s parameters population public JsonResult

  • 0

I think I’ve found a bug in ASP.NET MVC controller’s parameters population

public JsonResult Lookup(
    string q_word, string primary_key, 
    int per_page, int page_num)

If the q_word posted value is empty string, q_word will receive an empty string. Whereas if you pack those parameters together (DRY principle) in an object, the behavior is different, empty string becomes null.

public class LookupArg
{
    public string q_word { get; set; }

    public string primary_key { get; set; }
    public int per_page { get; set; }
    public int page_num { get; set; }

    public string another_word { get; set; }
}


public JsonResult TesterA(
        string q_word, string another_word, string primary_key, 
        int per_page, int page_num)
{
    return Json(
                new { q_word, primary_key, per_page, page_num, another_word},
                JsonRequestBehavior.AllowGet);
}

public JsonResult TesterB(LookupArg la)
{
    return Json(
                new { la.q_word, la.primary_key, la.per_page, la.page_num, 
                      la.another_word }, 
                JsonRequestBehavior.AllowGet);
}

http://localhost:19829/Product/TesterA?q_word=&primary_key=id&per_page=10&page_num=1&another_word=
Has this output:

{"q_word":"","primary_key":"id","per_page":10,"page_num":1,"another_word":""}

http://localhost:19829/Product/TesterB?q_word=&primary_key=id&per_page=10&page_num=1&another_word=
Has this output:

{"q_word":null,"primary_key":"id","per_page":10,"page_num":1,"another_word":null}

I tried this too, but to no avail, same output, q_word and another_word are still nulls

public JsonResult TesterB(
   [Bind(Include = "q_word, primary_key, per_page, page_num, another_word")] 
   LookupArg la)

Is this sort of behavior expected? by design? should there be any difference if a value came from object or not?

  • 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-24T09:41:04+00:00Added an answer on May 24, 2026 at 9:41 am

    You could decorate the property with the [DisplayFormat] attribute if you want to override this behavior which is by design since ASP.NET MVC 2 (it wasn’t the case in ASP.NET MVC 1, you may checkout the following blog post):

    public class LookupArg
    {
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string q_word { get; set; }
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I have found a bug when setting or getting the Me.Top property
I think I've stumbled upon a bug in the .NET (or the native windows
Think of this: A view controller's view is added as subview to another view.
Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I
I think the file that is produced is an .asm file, any idea how
I think most people know how to do this via the GUI (right click
I think most people here understand the importance of fully automated builds. The problem
I think this is specific to IE 6.0 but... In JavaScript I add a
I think it can be done by applying the transformation matrix of the scenegraph

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.