2

I am trying to learn ASP.Net MVC and I wanted to post array of JSON objects to the server and sent it back to the client side. But I am getting strange results. Everything was fine without adding the fourth variable (bool Required). I also tried to change for example true to "true" in JavaScript part that post the JSON, but I got the same strange results back from the server. The result of POST were the same in both using both JavaScript and POSTMAN, I think the problem is with Server side code.

Any help would be great.

Here is my controller code:

public ActionResult GetResult()
{
    List<SurveyDetails> tableList = new List<SurveyDetails>();
    tableList.Add(new SurveyDetails { Id = 500, Question = "where are you from", Answer = 2, Required = true });
    tableList.Add(new SurveyDetails { Id = 501, Question = "how old are you", Answer = 1, Required = false });
    tableList.Add(new SurveyDetails { Id = 502, Question = "what is your first car", Answer = 2, Required = false });
    tableList.Add(new SurveyDetails { Id = 503, Question = "do you have kids", Answer = 1, Required = true });
    return Json(tableList, JsonRequestBehavior.AllowGet);
}

    [HttpPost]
    public ActionResult GetResult(List<Table> list)
    {
        return Json(list);
    }

Here is my object declaration:

namespace CapstoneProject.Models
{
    public class SurveyDetails
    {
        public int Id { get; set; }
        public string Question { get; set; }
        public int Answer { get; set; }
        public bool Required { get; set; }
    }
}

Here is what I am getting from the server (GET Request):

[
    {
        "Id": 500,
        "Question": "where are you from",
        "Answer": 2,
        "Required": true
    },
    {
        "Id": 501,
        "Question": "how old are you",
        "Answer": 1,
        "Required": false
    },
    {
        "Id": 502,
        "Question": "what is your first car",
        "Answer": 2,
        "Required": false
    },
    {
        "Id": 503,
        "Question": "do you have kids",
        "Answer": 1,
        "Required": true
    }
]

And here the strange results that I am getting back from the server after POSTing what I have received in GET request:

[
    {
        "BackImageUrl": "",
        "Caption": "",
        "CaptionAlign": 0,
        "CellPadding": -1,
        "CellSpacing": -1,
        "GridLines": 0,
        "HorizontalAlign": 0,
        "SupportsDisabledAttribute": false,
        "Rows": [],
        "AccessKey": "",
        "Attributes": {
            "Keys": [],
            "Count": 0,
            "CssStyle": {
                "Keys": [],
                "Count": 0,
                "Value": null
            }
        },
        "BackColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "BorderColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "BorderWidth": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "BorderStyle": 0,
        "ControlStyle": {
            "BackImageUrl": "",
            "CellPadding": -1,
            "CellSpacing": -1,
            "GridLines": 0,
            "HorizontalAlign": 0,
            "BackColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "BorderColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "BorderWidth": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "BorderStyle": 0,
            "CssClass": "",
            "Font": {
                "Bold": false,
                "Italic": false,
                "Name": "",
                "Names": [],
                "Overline": false,
                "Size": {
                    "IsEmpty": true,
                    "Type": 0,
                    "Unit": {
                        "IsEmpty": true,
                        "Type": 1,
                        "Value": 0
                    }
                },
                "Strikeout": false,
                "Underline": false
            },
            "ForeColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "Height": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "IsEmpty": true,
            "RegisteredCssClass": "",
            "Width": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "Site": null,
            "Container": null
        },
        "ControlStyleCreated": true,
        "CssClass": "",
        "Style": {
            "Keys": [],
            "Count": 0,
            "Value": null
        },
        "Enabled": true,
        "EnableTheming": true,
        "Font": {
            "Bold": false,
            "Italic": false,
            "Name": "",
            "Names": [],
            "Overline": false,
            "Size": {
                "IsEmpty": true,
                "Type": 0,
                "Unit": {
                    "IsEmpty": true,
                    "Type": 1,
                    "Value": 0
                }
            },
            "Strikeout": false,
            "Underline": false
        },
        "ForeColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "HasAttributes": false,
        "Height": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "SkinID": "",
        "TabIndex": 0,
        "ToolTip": "",
        "Width": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "ClientIDMode": 0,
        "ClientID": "500",
        "ID": "500",
        "EnableViewState": true,
        "ViewStateMode": 0,
        "NamingContainer": null,
        "BindingContainer": null,
        "DataItemContainer": null,
        "DataKeysContainer": null,
        "Page": null,
        "RenderingCompatibility": {
            "Major": 4,
            "Minor": 5,
            "Build": -1,
            "Revision": -1,
            "MajorRevision": -1,
            "MinorRevision": -1
        },
        "TemplateControl": null,
        "Parent": null,
        "TemplateSourceDirectory": "/Survey",
        "AppRelativeTemplateSourceDirectory": "~/Survey/",
        "Site": null,
        "Visible": true,
        "UniqueID": "500",
        "Controls": [],
        "ValidateRequestMode": 0
    },
    {
        "BackImageUrl": "",
        "Caption": "",
        "CaptionAlign": 0,
        "CellPadding": -1,
        "CellSpacing": -1,
        "GridLines": 0,
        "HorizontalAlign": 0,
        "SupportsDisabledAttribute": false,
        "Rows": [],
        "AccessKey": "",
        "Attributes": {
            "Keys": [],
            "Count": 0,
            "CssStyle": {
                "Keys": [],
                "Count": 0,
                "Value": null
            }
        },
        "BackColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "BorderColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "BorderWidth": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "BorderStyle": 0,
        "ControlStyle": {
            "BackImageUrl": "",
            "CellPadding": -1,
            "CellSpacing": -1,
            "GridLines": 0,
            "HorizontalAlign": 0,
            "BackColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "BorderColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "BorderWidth": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "BorderStyle": 0,
            "CssClass": "",
            "Font": {
                "Bold": false,
                "Italic": false,
                "Name": "",
                "Names": [],
                "Overline": false,
                "Size": {
                    "IsEmpty": true,
                    "Type": 0,
                    "Unit": {
                        "IsEmpty": true,
                        "Type": 1,
                        "Value": 0
                    }
                },
                "Strikeout": false,
                "Underline": false
            },
            "ForeColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "Height": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "IsEmpty": true,
            "RegisteredCssClass": "",
            "Width": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "Site": null,
            "Container": null
        },
        "ControlStyleCreated": true,
        "CssClass": "",
        "Style": {
            "Keys": [],
            "Count": 0,
            "Value": null
        },
        "Enabled": true,
        "EnableTheming": true,
        "Font": {
            "Bold": false,
            "Italic": false,
            "Name": "",
            "Names": [],
            "Overline": false,
            "Size": {
                "IsEmpty": true,
                "Type": 0,
                "Unit": {
                    "IsEmpty": true,
                    "Type": 1,
                    "Value": 0
                }
            },
            "Strikeout": false,
            "Underline": false
        },
        "ForeColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "HasAttributes": false,
        "Height": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "SkinID": "",
        "TabIndex": 0,
        "ToolTip": "",
        "Width": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "ClientIDMode": 0,
        "ClientID": "501",
        "ID": "501",
        "EnableViewState": true,
        "ViewStateMode": 0,
        "NamingContainer": null,
        "BindingContainer": null,
        "DataItemContainer": null,
        "DataKeysContainer": null,
        "Page": null,
        "RenderingCompatibility": {
            "Major": 4,
            "Minor": 5,
            "Build": -1,
            "Revision": -1,
            "MajorRevision": -1,
            "MinorRevision": -1
        },
        "TemplateControl": null,
        "Parent": null,
        "TemplateSourceDirectory": "/Survey",
        "AppRelativeTemplateSourceDirectory": "~/Survey/",
        "Site": null,
        "Visible": true,
        "UniqueID": "501",
        "Controls": [],
        "ValidateRequestMode": 0
    },
    {
        "BackImageUrl": "",
        "Caption": "",
        "CaptionAlign": 0,
        "CellPadding": -1,
        "CellSpacing": -1,
        "GridLines": 0,
        "HorizontalAlign": 0,
        "SupportsDisabledAttribute": false,
        "Rows": [],
        "AccessKey": "",
        "Attributes": {
            "Keys": [],
            "Count": 0,
            "CssStyle": {
                "Keys": [],
                "Count": 0,
                "Value": null
            }
        },
        "BackColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "BorderColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "BorderWidth": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "BorderStyle": 0,
        "ControlStyle": {
            "BackImageUrl": "",
            "CellPadding": -1,
            "CellSpacing": -1,
            "GridLines": 0,
            "HorizontalAlign": 0,
            "BackColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "BorderColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "BorderWidth": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "BorderStyle": 0,
            "CssClass": "",
            "Font": {
                "Bold": false,
                "Italic": false,
                "Name": "",
                "Names": [],
                "Overline": false,
                "Size": {
                    "IsEmpty": true,
                    "Type": 0,
                    "Unit": {
                        "IsEmpty": true,
                        "Type": 1,
                        "Value": 0
                    }
                },
                "Strikeout": false,
                "Underline": false
            },
            "ForeColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "Height": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "IsEmpty": true,
            "RegisteredCssClass": "",
            "Width": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "Site": null,
            "Container": null
        },
        "ControlStyleCreated": true,
        "CssClass": "",
        "Style": {
            "Keys": [],
            "Count": 0,
            "Value": null
        },
        "Enabled": true,
        "EnableTheming": true,
        "Font": {
            "Bold": false,
            "Italic": false,
            "Name": "",
            "Names": [],
            "Overline": false,
            "Size": {
                "IsEmpty": true,
                "Type": 0,
                "Unit": {
                    "IsEmpty": true,
                    "Type": 1,
                    "Value": 0
                }
            },
            "Strikeout": false,
            "Underline": false
        },
        "ForeColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "HasAttributes": false,
        "Height": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "SkinID": "",
        "TabIndex": 0,
        "ToolTip": "",
        "Width": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "ClientIDMode": 0,
        "ClientID": "502",
        "ID": "502",
        "EnableViewState": true,
        "ViewStateMode": 0,
        "NamingContainer": null,
        "BindingContainer": null,
        "DataItemContainer": null,
        "DataKeysContainer": null,
        "Page": null,
        "RenderingCompatibility": {
            "Major": 4,
            "Minor": 5,
            "Build": -1,
            "Revision": -1,
            "MajorRevision": -1,
            "MinorRevision": -1
        },
        "TemplateControl": null,
        "Parent": null,
        "TemplateSourceDirectory": "/Survey",
        "AppRelativeTemplateSourceDirectory": "~/Survey/",
        "Site": null,
        "Visible": true,
        "UniqueID": "502",
        "Controls": [],
        "ValidateRequestMode": 0
    },
    {
        "BackImageUrl": "",
        "Caption": "",
        "CaptionAlign": 0,
        "CellPadding": -1,
        "CellSpacing": -1,
        "GridLines": 0,
        "HorizontalAlign": 0,
        "SupportsDisabledAttribute": false,
        "Rows": [],
        "AccessKey": "",
        "Attributes": {
            "Keys": [],
            "Count": 0,
            "CssStyle": {
                "Keys": [],
                "Count": 0,
                "Value": null
            }
        },
        "BackColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "BorderColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "BorderWidth": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "BorderStyle": 0,
        "ControlStyle": {
            "BackImageUrl": "",
            "CellPadding": -1,
            "CellSpacing": -1,
            "GridLines": 0,
            "HorizontalAlign": 0,
            "BackColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "BorderColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "BorderWidth": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "BorderStyle": 0,
            "CssClass": "",
            "Font": {
                "Bold": false,
                "Italic": false,
                "Name": "",
                "Names": [],
                "Overline": false,
                "Size": {
                    "IsEmpty": true,
                    "Type": 0,
                    "Unit": {
                        "IsEmpty": true,
                        "Type": 1,
                        "Value": 0
                    }
                },
                "Strikeout": false,
                "Underline": false
            },
            "ForeColor": {
                "R": 0,
                "G": 0,
                "B": 0,
                "A": 0,
                "IsKnownColor": false,
                "IsEmpty": true,
                "IsNamedColor": false,
                "IsSystemColor": false,
                "Name": "0"
            },
            "Height": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "IsEmpty": true,
            "RegisteredCssClass": "",
            "Width": {
                "IsEmpty": true,
                "Type": 1,
                "Value": 0
            },
            "Site": null,
            "Container": null
        },
        "ControlStyleCreated": true,
        "CssClass": "",
        "Style": {
            "Keys": [],
            "Count": 0,
            "Value": null
        },
        "Enabled": true,
        "EnableTheming": true,
        "Font": {
            "Bold": false,
            "Italic": false,
            "Name": "",
            "Names": [],
            "Overline": false,
            "Size": {
                "IsEmpty": true,
                "Type": 0,
                "Unit": {
                    "IsEmpty": true,
                    "Type": 1,
                    "Value": 0
                }
            },
            "Strikeout": false,
            "Underline": false
        },
        "ForeColor": {
            "R": 0,
            "G": 0,
            "B": 0,
            "A": 0,
            "IsKnownColor": false,
            "IsEmpty": true,
            "IsNamedColor": false,
            "IsSystemColor": false,
            "Name": "0"
        },
        "HasAttributes": false,
        "Height": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "SkinID": "",
        "TabIndex": 0,
        "ToolTip": "",
        "Width": {
            "IsEmpty": true,
            "Type": 1,
            "Value": 0
        },
        "ClientIDMode": 0,
        "ClientID": "503",
        "ID": "503",
        "EnableViewState": true,
        "ViewStateMode": 0,
        "NamingContainer": null,
        "BindingContainer": null,
        "DataItemContainer": null,
        "DataKeysContainer": null,
        "Page": null,
        "RenderingCompatibility": {
            "Major": 4,
            "Minor": 5,
            "Build": -1,
            "Revision": -1,
            "MajorRevision": -1,
            "MinorRevision": -1
        },
        "TemplateControl": null,
        "Parent": null,
        "TemplateSourceDirectory": "/Survey",
        "AppRelativeTemplateSourceDirectory": "~/Survey/",
        "Site": null,
        "Visible": true,
        "UniqueID": "503",
        "Controls": [],
        "ValidateRequestMode": 0
    }
]
Community
  • 1
  • 1
Node.JS
  • 1,042
  • 6
  • 44
  • 114
  • Why does your `GetResult()` method take a `List` when your class is called `SurveyResult`? If I simply do `Debug.WriteLine(JsonConvert.SerializeObject(new System.Web.UI.WebControls.Table [1] { new System.Web.UI.WebControls.Table() } , Formatting.Indented))` I see roughly the same JSON you are seeing.
    – dbc Mar 12 '15 at 05:53

1 Answers1

3

GetResult(List<Table> list) List<Table>

I think this make you fail,It is a class from System.Web.UI.WebControls, a webform control.change it to List<SurveyDetails> and try


I donot have 50 point ,can not add comment ,so just leave a answer

clijiac
  • 117
  • 3