【发布时间】:2013-12-03 17:12:38
【问题描述】:
所以我已经看到 Web API 2 控制器返回 HttpResponse 和实际对象。示例:
public HttpResponseMessage Get(string id)
{
var app = apps.Single(c => c.Id == id);
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ObjectContent<object>(app,
Configuration.Formatters.JsonFormatter)
};
}
或
public Application Get(string id)
{
return apps.Single(c => c.Id == id);
}
我的问题是“正确”的方式? #2 要短得多,但最好是做 #1 还是 #2 自动做 #1 ... ?
【问题讨论】:
标签: asp.net .net asp.net-web-api