Skip to content

Instantly share code, notes, and snippets.

@rafaelss
Created June 30, 2009 15:53
Show Gist options
  • Save rafaelss/138225 to your computer and use it in GitHub Desktop.
Save rafaelss/138225 to your computer and use it in GitHub Desktop.
using System.Web.Mvc;
/*
* return new SimpleResult("Hello World");
* return new SimpleResult(1);
* return new SimpleResult(1257.14);
* return new SimpleResult(true);
*/
namespace Custom.Mvc
{
public class SimpleJsonResult : ActionResult
{
private JsonResult result = new JsonResult();
public SimpleJsonResult(object content)
{
result.ContentType = "text/javascript";
result.Data = content;
}
public override void ExecuteResult(ControllerContext context)
{
result.ExecuteResult(context);
}
}
}
using System.Web.Mvc;
/*
* return new SimpleJsonResult(new { success = true });
*/
namespace Custom.Mvc
{
public class SimpleResult : ActionResult
{
private ContentResult result = new ContentResult();
public SimpleResult(string content)
{
result.Content = content;
}
public SimpleResult(int content)
{
result.Content = content.ToString();
}
public SimpleResult(double content)
{
result.Content = content.ToString();
}
public SimpleResult(bool content)
{
result.Content = content ? "true" : "false";
}
public override void ExecuteResult(ControllerContext context)
{
result.ExecuteResult(context);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment