views:

189

answers:

2

Hi,

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?

+2  A: 

You want to do a return with Json not Content

return Json(new { first = "1", second ="2" });
RM
+2  A: 

How about letting the system deal with it:

    public ActionResult TestAjax(string testID)
    {
        return Json(new {first = 1, second = 2});
    }
Marc Gravell
yeah if I added "applicaton/json" that worked also, thanks!
mrblah