【发布时间】:2015-03-04 13:48:03
【问题描述】:
我下面的简单 Action 方法总是返回 JSON,不管 Accept 标头设置为 application/xml。内容协商适用于我在同一控制器中的其他操作。
public HttpResponseMessage GetOrder(int id) {
var orderDescription = mydbc.tbl_job_versions.AsNoTracking().Where(t => t.JobId == id)
.Select(t => new{Id = t.JobId, Description = t.Brand + " " + t.Variety + " " + t.Promotion + " " + t.MarketSegment }).FirstOrDefault ();
if (orderDescription == null) {
return new HttpResponseMessage(HttpStatusCode.NotFound);
}
else {
return Request.CreateResponse((HttpStatusCode)200, orderDescription);
}
}
什么可能导致它不执行内容协商,而是总是返回 JSON?
【问题讨论】:
标签: asp.net-web-api2 content-negotiation