HttpPost方法不返回值

时间:2017-11-11 02:02:08

标签: c# post odata

我做了以下方法。当我从Advance rest客户端点击它然后我看到下面的输出,但我没有看到值。在调试时,我可以看到PersonDetail类类型的lstPersonDetail中的3条记录。请告诉我有什么遗漏的吗?

输出:

{
    @odata.context: "http://localhost:9912/API-service/$metadata#System.Collections.Generic.List_1OfPersonDetail"
    Capacity: 4
}

方法:

[EnableQuery]
[HttpPost]
[ODataRoute("GetPersonDetails()")]
public List<PersonDetail> GetPersonDetails(ODataActionParameters parameters)
{
    List<PersonDetail> lstPersonDetail = new List<PersonDetail>();
    if (parameters == null)
    {
        return lstPersonDetail;
    }

    IEnumerable<string> firstNames = parameters["firstNames"] as IEnumerable<string>;
    firstNames = firstNames.ToList();

    try
    {
        if (firstNames != null && firstNames.Count() > 0)
        {
            using (DBEntities db = new DBEntities())
            {
                lstPersonDetail = (from x in db.PersonData
                              from t in firstNames
                              where x.PersonFirstName.ToLower().Contains(t.ToLower())
                              select new PersonDetail
                              {
                                  FullName = x.FullName,
                                  City = x.City
                              }).ToList();
            }
        }
    }
    catch (Exception ex)
    {

    }

    return lstPersonDetail;
}

public class PersonDetail
{
    public string FullName { get; set; }
    public string City { get; set; }
}

0 个答案:

没有答案