Reputation: 1798
The below code is returning [object Object] not a string. How can I get it to return the correct string representation? I am using ASP.NET MVC4 C#.
public JsonResult Names(string name)
{
var a = db.NamesToGet.Select(e => new
{
name = e.Names
});
return Json(a, JsonRequestBehavior.AllowGet);
}
Upvotes: 0
Views: 174
Reputation: 1898
Access it with data.name
or substitute data
to your json variable name.
$.get("/Controller/GetName", function(data) {
alert(data.name);
//or alert(data[0].name);
});
Upvotes: 1