ResourceResult
History Key
- New content
Removed content
Recent Versions
Choose two versions to compare, or click the link to view it.
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)