MVC WebAPI默认绑定永远不会返回,在命中控制器操作时会占用所有可用内存。
如果我从模型中移除Result
,事情就会奏效。我无法解释的是,Media
的构造函数中的断点得到了隐藏,尽管请求没有为result
发送值。
解释是什么?
请求:
http://site/api/Media?companyId=1234&excludeProductId=4321&query=&result=&pageSize=25&totalItems=0&directPageSelectorsCount=5&totalPages=0¤tPage=1
控制器:
[HttpGet]
public HttpResponseMessage Get([FromUri]MediaSearch search)
型号:
public class PaginatorMeta
{
public int DirectPageSelectorsCount { get; set; }
public int TotalPages { get; set; }
public int CurrentPage { get; set; }
}
public class MediaSearch : PaginatorMeta
{
public int CompanyId { get; set; }
public int ExcludeProductId { get; set; }
public string Query { get; set; }
public IList<Media> Result { get; set; }
public ushort PageSize { get; set; }
public int TotalItems
{
get
{
return this.Result.Count;
}
}
public MediaSearch()
{
Result = new List<Media>();
}
public class Media
{
public Media()
{
this.MediaRelationMatches = new List<MediaRelationMatch>();
}
public long ID { get; set; }
public string Descr { get; set; }
public string UrlVal { get; set; }
public string TypeCode { get; set; }
public string ImageCode { get; set; }
public bool IsProc { get; set; }
public int CompanyID { get; set; }
public ICollection<MediaRelationMatch> MediaRelationMatches { get; set; }
}
public class MediaRelationMatch
{
public long RelationId { get; set; }
public long MediaId { get; set; }
}
}