Returning Json from an MVC controller that extends Apicontroller

asp.net-mvc, json

Solution

In Asp.net Web Api you don't have ActionResults anymore. You simply return the object you need. The framework converts the object to the proper response (json, xml or other types)

[HttpGet]
public IEnumerable<string> GetUsers(SocialRequest request)
{
    return _applicationsService.GetUserss(request);
}

Problem

I'm trying to return a Json string from an MVC controller in a WebAPI application, but am unable to use `return Json(...` because the class being used extends `ApiController` and not `Controller` (I believe). Is there an alternative method to do what I'm trying to do (e.g. return a different type)? Or a workaround? This is my controller code: ``` public class SocialController : ApiController { public ActionResult Get(SocialRequest request) // or JsonResult? { JavaScriptSerializer js = new JavaScriptSerializer(); string jsontest = js.Serialize(request); // just serializing back and forth for testing return Json(jsontest, JsonRequestBehavior.AllowGet); } } ``` The error I'm receiving is "System.Web.Helpers.Json is a type but is used like a variable." I've found the following related SO question but it hasn't solved it for me, if anyone can elaborate I'd really appreciate it (and dish out the rep points): Why Json() Function is unknown

Original source