当我保留在Queryable中时,它会给出以下错误,如果我使用装饰器,我将如何处理抛出错误[可查询]:
查询无法应用于&System; Net.Net.Http.StringContent'类型的响应内容。响应内容必须是ObjectContent。
[HttpGet]
[Queryable]
[ActionName("ById")]
[ResponseType(typeof(Example))]
public IQueryable<Example> Get(ODataQueryOptions opts, Guid actionuniqueid)
{
if (actionuniqueid.ToString() == "00000000-0000-0000-0000-000000000000")
{
var resp = new HttpResponseMessage(HttpStatusCode.NoContent)
{
Content =
new StringContent(
string.Format(
"No Example for ID: {0}", actionuniqueid)),
ReasonPhrase = "Missing parameter"
};
throw new HttpResponseException(resp);
}
答案 0 :(得分:0)
尝试使用:
var resp = new HttpResponseMessage(HttpStatusCode.NoContent)
{
Content =
new ObjectContent(typeof(string),
string.Format("No Example for ID: {0}", actionuniqueid)),
new JsonMediaTypeFormatter()),
ReasonPhrase = "Missing parameter"
};