jcr*_*898 4 asp.net asp.net-mvc-4 asp.net-web-api
我遇到了WebAPI的问题,返回空500.
这是数据类.
public class Comment
{
public int Id { get; set; }
public string Content { get; set; }
public string Email { get; set; }
public bool IsAnonymous { get; set; }
public int ReviewId { get; set; }
public Review Review { get; set; }
}
public class Review
{
public int Id { get; set; }
public string Content { get; set; }
public int CategoryId { get; set; }
public string Topic { get; set; }
public string Email { get; set; }
public bool IsAnonymous { get; set; }
public virtual Category Category { get; set; }
public virtual ICollection<Comment> Comments { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是来自ReviewRepository.cs的代码
public Review Get(int id)
{
return _db.Reviews.Include("Comments").SingleOrDefault(r => r.Id == id);
}
Run Code Online (Sandbox Code Playgroud)
以及来自ReviewController.cs的代码
public HttpResponseMessage Get(int id)
{
var category = _reviewRepository.Get(id);
if (category == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
return Request.CreateResponse(HttpStatusCode.OK, category);
}
Run Code Online (Sandbox Code Playgroud)
无论我做什么,从/ api/reviews/1返回的响应都是500错误.调试时,类别是正确的,加载了所有注释.
我试过了GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
,但那没有用.我在这里不知所措!
归档时间: |
|
查看次数: |
2363 次 |
最近记录: |