I am making a web api call and I want the controller method to return data in json format.
The model class I used is User.cs :
public partial class User
{
public int UserID { get; set; }
public string city { get; set; }
public string email { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string phone { get; set; }
public string password { get; set; }
}
I want to return all the users email data in json format through the following controller method.
public string GetUsers()
{
IEnumerable<User> users = db.Users.ToList();
var jsonSerialiser = new JavaScriptSerializer();
var json = jsonSerialiser.Serialize(users);
return json;
//string json = JsonConvert.SerializeObject(users);
//return json;
}
All I am getting is empty json like:
[]
Please help. I have covered all the methods recommended on stackoverflow.