using System.Web.Script.Serialization; using System.Web.Mvc; namespace View_Engine_Demo { public class JsonViewEngine : IViewEngine { public void RenderView(ViewContext viewContext) { string json = new JavaScriptSerializer() .Serialize(viewContext.ViewData); viewContext.HttpContext.Response.Clear(); viewContext.HttpContext.Response.ContentType = "application/json"; viewContext.HttpContext.Response.Write(json); } } }