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

  • Home
  • SEARCH
  • 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 5936915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:27:56+00:00 2026-05-22T15:27:56+00:00

In my class i’ve got: [DataMember(Name = jsonMemberName, EmitDefaultValue = false, IsRequired = false)]

  • 0

In my class i’ve got:

[DataMember(Name = "jsonMemberName", EmitDefaultValue = false, 
    IsRequired = false)]
public List<string> Member { get; set; }

After passing the object through controller’s Json(obj) that retruns System.Web.Mvc.JsonResult: i’ve got serialized json: {Member:…} but not {jsonMemberName:…}, so it doesn’t look at DataMember(Name = “jsonMemberName”).

If I use serialization from System.Runtime.Serialization.Json everithing’s works fine as expected.

What can be 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-05-22T15:27:57+00:00Added an answer on May 22, 2026 at 3:27 pm

    The JsonResult action which you are returning from the controller action (using return Json(...)) internally relies on the JavaScriptSerializer class. This class doesn’t take into account any DataMember attributes on your model.

    You could write a custom ActionResult which uses the serializer in the System.Runtime.Serialization.Json namespace.

    For example:

    public class MyJsonResult : JsonResult
    {
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;
            if (!string.IsNullOrEmpty(ContentType))
            {
                response.ContentType = ContentType;
            }
            else
            {
                response.ContentType = "application/json";
            }
            if (ContentEncoding != null)
            {
                response.ContentEncoding = this.ContentEncoding;
            }
            if (Data != null)
            {
                var serializer = new DataContractJsonSerializer(Data.GetType());
                serializer.WriteObject(response.OutputStream, Data);
            }
        }
    }
    

    and then in your controller action:

    public ActionResult Foo()
    {
        var model = ...
        return new MyJsonResult { Data = model };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class TreeNode { public string Value { get; set;} public Collection<TreeNode> Nodes { get;
class Person { string name; public Person(string name) { this.name = name; } public
class MyBase { protected object PropertyOfBase { get; set; } } class MyType :
class A { public static void main(String[] args) { A a = new A();
class Catalog { // string StationTitle; string StationLocation; public: string StationTitle; Catalog() { StationTitle
class ParentClass { public function list() { foreach ($this as $property => $value) {
Class Carro { String name String marca String matricula } Class CarroMovel{ String pro1
class foo { public: void set(const int a) {b=a;} private: int b; }; Here
class Area { String name String description static constraints = { } _ class
class Tag(models.Model): name = models.CharField(maxlength=100) class Blog(models.Model): name = models.CharField(maxlength=100) tags = models.ManyToManyField(Tag) Simple

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.