user514494
user514494

Reputation: 39

Need to return json data from a controller?

I need to return some json data from controller. Anyone know how to do it?

Upvotes: 0

Views: 66

Answers (2)

David
David

Reputation: 218798

You could do this manually:

public ActionResult MyAction() {
    return Content("this is a string literal, which can be HTML, XML, JSON, etc.");
}

But I think I remember an actual JSON return object before, though I've never used it. Something like:

public ActionResult MyAction() {
  return Json(new {thing1="first thing", thing2="second thing"});
}

Upvotes: 1

xandy
xandy

Reputation: 27411

Simple. it's called JsonResult

Upvotes: 2

Related Questions