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?

2 Answers 2

3

How about letting the system deal with it:

    public ActionResult TestAjax(string testID)
    {
        return Json(new {first = 1, second = 2});
    }
Sign up to request clarification or add additional context in comments.

Comments

2

You want to do a return with Json not Content

return Json(new { first = "1", second ="2" });

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.