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. Everything is fine when I use Postman, but it doesn't work on actual web page. I think the problem is either with jQuery code that posts the array or ASP.Net code that is not able to parse the array.
Here is my controller code:
[System.Web.Mvc.HttpPost]
public ActionResult GetResult(List<Table> list)
{
return Json(list);
}
Here is my object declaration:
public class Table
{
public int Id { get; set; }
public String Question { get; set; }
public int Answer { get; set; }
}
Here is jQuery code that posts the data:
$.post("./GetResult", JSON.stringify(tableData), function (data, status) { alert(status); }, "json");
and tableData is an Array of JSON like this:
[
{
"Id": 500,
"Question": "where are you from",
"Answer": 2
},
{
"Id": 501,
"Question": "how old are you",
"Answer": 1
},
{
"Id": 502,
"Question": "what is your first car",
"Answer": 2
},
{
"Id": 503,
"Question": "do you have kids",
"Answer": 1
}
]
Also, I can see that my code goes through the post controller but it is empty or null.
Here is the link of my csHTML file.