Returning Empty Json Object-Collection of common programming errors
In C# we have properties which (in C# 3+) can be automatically created.
public class A
{
public string Name { get; set; }
}
Secondly you will need to return your object wrapped in a new object in order for the JSON to return correctly. You do not need to serialize the object yourself (since you could just return it as an ActionResult
otherwise).
public JsonResult Hello()
{
A obj = new A();
obj.Name = "Abc";
return Json(new { obj }, JsonRequestBehavior.AllowGet);
}
This will create a new Json object {"obj":{"Name":"Abc"}}