Version 1, last updated by Andrew Davey at May 28, 2009 03:33 UTC
ResourceResult
The ResourceResult class derives from ActionResult. It adds status code, content negotiation support for view models and a handy fluent interface to define the response headers.
// in an action method
return OK(customerViewModel)
.WithCookie(new HttpCookie("visitorid", xyz))
.WithHeader('X-Info', foo)
.WithCache(c => c.SetExpires(DateTime.Now.AddSeconds(30));
The OK function call creates a new ResourceAction object, with status code 200 and the view model set as the response resource. You can create ResourceAction directly if needed, but the HTTP status code functions read better.
The response content type can be forced, if needed, using the "As*" fluent methods:
return OK(customerViewModel).AsJson(); // or these: AsXml(), AsText(), As(typestring)