2

in .NET MVC my action looks like:

public ActionResult TestAjax(string testID)
{

    return Content(@"{first: ""1"", second : ""2""}");
}

In my JavaScript I am doing:

function(data)
{
      alert(data.first);
}

I am getting [object Object] as the output, why is that?

Is my JSON string wrong?

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
mrblah
  • 99,669
  • 140
  • 310
  • 420

2 Answers2

3

How about letting the system deal with it:

    public ActionResult TestAjax(string testID)
    {
        return Json(new {first = 1, second = 2});
    }
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
2

You want to do a return with Json not Content

return Json(new { first = "1", second ="2" });
Rosstified
  • 4,047
  • 2
  • 25
  • 33