0

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);
}
1
  • 1
    return a as .ToArray() or .ToList(). Commented Nov 7, 2013 at 22:29

2 Answers 2

2

try

var a = db.NamesToGet.Select(e=>e.Names);
Sign up to request clarification or add additional context in comments.

1 Comment

You shouldn't have try without catch
1

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);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.