I have noticed that ASP.NET MVC 3 introduces a HttpStatusCodeResult action result. How do we do the equivalent in ASP.NET MVC 2? I want to return a 410 code.
+1
A:
You could create your own HttpStatusCodeResult which might look something like this:
public class HttpStatusCodeResult : ActionResult
{
private readonly int code;
public HttpStatusCodeResult(int code)
{
this.code = code;
}
public override void ExecuteResult(System.Web.Mvc.ControllerContext context)
{
context.HttpContext.Response.StatusCode = code;
}
}
Matthew Manela
2010-09-26 22:46:26
A:
I found something here that does just what I want http://weblogs.asp.net/gunnarpeipman/archive/2010/07/28/asp-net-mvc-3-creating-httpstatuscoderesult-with-view-based-body.aspx
Craig
2010-09-27 22:15:38