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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:50:40+00:00 2026-06-14T00:50:40+00:00

I have a action which returns an JsonResult for an object of a particular

  • 0

I have a action which returns an JsonResult for an object of a particular class. I have decorated the properties of this class with some attrib to avoid null fields. Class definition is:

    private class GanttEvent
    {
        public String name { get; set; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public String desc { get; set; }

        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public List<GanttValue> values { get; set; }
    }

And in my Action i use an object

    var res = new List<GanttEvent>();

which I return using:

    return Json(res, JsonRequestBehavior.AllowGet);

Unfortunatelly, I’m still receiving null values at output:

    [{"name":"1.1 PREVIOS AL INICIO ","desc":null,"values":null},{"name":"F04-PGA-S10","desc":"Acta preconstrucción","values":null},{"name":"F37-PGA-S10","desc":"Plan de inversión del anticipo","values":null},{"name":"F09-PGA-S10","desc":"Acta de vecindad","values":null},{"name":"F05-PGA-S10","desc":"Acta de inicio","values":null},{"name":"F01-PGA-S10","desc":"Desembolso de anticipo","values":null}]

Am I missing something or doing something wrong?

  • 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-14T00:50:42+00:00Added an answer on June 14, 2026 at 12:50 am

    As stated by Brad Christie, MVC4 stills uses JavaScriptSerializer, so in order to get your object serialized by Json.Net, you will have to perform several steps.

    First, inherit a new class JsonNetResult from JsonResult as follows (based on this solution):

    public class JsonNetResult : JsonResult
    {
        public JsonNetResult()
        {
            this.ContentType = "application/json";
        }
    
        public JsonNetResult(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior jsonRequestBehavior)
        {
            this.ContentEncoding = contentEncoding;
            this.ContentType = !string.IsNullOrWhiteSpace(contentType) ? contentType : "application/json";
            this.Data = data;
            this.JsonRequestBehavior = jsonRequestBehavior;
        }
    
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");
    
            var response = context.HttpContext.Response;
    
            response.ContentType = !String.IsNullOrEmpty(ContentType) ? ContentType : "application/json";
    
            if (ContentEncoding != null)
                response.ContentEncoding = ContentEncoding;
    
            if (Data == null)
                return;
    
            // If you need special handling, you can call another form of SerializeObject below
            var serializedObject = JsonConvert.SerializeObject(Data, Formatting.None);
            response.Write(serializedObject);
        }
    }
    

    Then, in your controller, override the Json method to use the new class:

    protected override JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior)
    {
        return new JsonNetResult(data, contentType, contentEncoding, behavior);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have controller action which returns JsonResult and is consumed by jquery ajax get
Is it ok to have action which returns object type? What implications may it
I have controller users . In this controller I have action account which is
I have got an action which takes in an argument it goes like this
I have got Sinatra/Rails app and an action which starts some long process. Ordinary
I have an action 'approval' that renders a view which displays some content from
I have a controller index action which returns json output. render :json => my_array.to_json
I have an AJAX controller action which returns JSON. The returned JSON is handled
I have a action result method in the conrtoller which returns a IList to
I have a .NET MVC controller action that returns a JsonResult to a YUI

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.