Craig
Craig

Reputation: 36826

HttpStatusCodeResult in ASP.NET MVC 2

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.

Upvotes: 2

Views: 1724

Answers (2)

Matthew Manela
Matthew Manela

Reputation: 16762

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;
    }
}

Upvotes: 5

Related Questions