为什么找不到这个特定的Repository方法?

时间:2014-02-13 19:37:42

标签: c# rest controller repository asp.net-web-api-routing

我的三个Web API方法中有两个工作正常;第三个没有 - 它咆哮我,Dobermanesque:“远程服务器返回错误(404)未找到”

以下是Controller方法:

[Route("api/Subdepartments/GetCount")]
public int GetCountOfSubdepartmentRecords(string serialNum)
{
    return _subdepartmentsRepository.GetCount(serialNum);
}

[Route("api/Subdepartments/GetAll")]
public IEnumerable<Subdepartment> GetAllSubdepartmentRecords(string serialNum)
{
    return _subdepartmentsRepository.GetAll(serialNum);
}

[Route("api/Subdepartments")]
public IEnumerable<Subdepartment> GetBatchFromID(string serialNum, int ID, int CountToFetch)
{
    return _subdepartmentsRepository.GetBatch(ID, CountToFetch, serialNum);
}

以下是存储库方法:

public int GetCount(string serialNum)
{
    LoadSubdepartments(serialNum);
    return subdepartments.Count;
}

public IEnumerable<Subdepartment> GetAll(string serialNum)
{
    LoadSubdepartments(serialNum);
    return subdepartments;
}

public IEnumerable<Subdepartment> GetBatch(int ID, int CountToFetch, string serialNum)
{
    LoadSubdepartments(serialNum);
    return subdepartments.Where(i => i.Id >= ID).Take(CountToFetch);
}

...这是我传递的URI:

http://localhost:28642/api/Subdepartments/GetCount?serialNum=8675309e9
http://localhost:28642/api/Subdepartments/GetAll?serialNum=8675309e9
http://localhost:28642/api/Subdepartments?serialNum=8675309e9&Int=1&CountToFetch=5

为什么GetCount()和GetAll()有效,而GetBatch()没有?

1 个答案:

答案 0 :(得分:1)

因为您的查询字符串中有Int=而不是ID=

因此,您传递的URI应为

http://localhost:28642/api/Subdepartments?serialNum=8675309e9&ID=1&CountToFetch=5