Question

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?

Was it helpful?

Solution

How about letting the system deal with it:

    public ActionResult TestAjax(string testID)
    {
        return Json(new {first = 1, second = 2});
    }

OTHER TIPS

You want to do a return with Json not Content

return Json(new { first = "1", second ="2" });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top