我下面的简单 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?