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.

2 Answers 2

5

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.