好的,这是我的问题:我正在用 javascript 创建一个 Windows 8 商店应用程序,它从用 asp 用 C# 编写的 API 获取其数据。商店一直在使用几种需要两个字段的方法(例如:发送员工 ID 和记录 ID 以验证记录是否属于员工并返回更多详细信息)。但是,由于某种原因,我有一种方法根本无法工作。这是控制器中的方法:
[HttpGet]
[ActionName("teste")]
public IEnumerable<EmployeeProjectViewModel> teste(int iUserMasterId, int iEmployeeOrganizationsId)
{
var Query = from eprojects in db.EmployeeProjects
where eprojects.UserMasterId == iUserMasterId
&& eprojects.Deleted == false
&& eprojects.EmployeeOrganizationsId == iEmployeeOrganizationsId
select new EmployeeProjectViewModel
{
EmployeeProjectsId = eprojects.EmployeeProjectsId,
UserMasterId = eprojects.UserMasterId,
Name = eprojects.ProjectName,
Month = eprojects.ProjectMonth,
Year = eprojects.ProjectYear,
URL = eprojects.ProjectURL,
Description = eprojects.ProjectDescription,
};
return Query;
}
和 routeConfig 代码:
routes.MapHttpRoute(
name: "teste",
routeTemplate: "api/{controller}/teste/{iUserMasterId}/{iEmployeeOrganizationsId}",
defaults: new
{
action = "teste"
});
它给我的错误是 404: Method not found in controller (verified with Fiddler)。但是控制器是正确的,因为控制器中有更多方法。我还注意到,同一控制器中也使用多个字段的其他方法最终也会失败。我究竟做错了什么?我已经将这两个代码与我拥有的其他控制器进行了比较,这些控制器也适用于多个字段,它们似乎都运行良好。
编辑:这是请求示例:
{"$id":"1","Message":"No HTTP resource was found that matches the request URI 'http://localhost:55105/api/EmployeeProjects/teste/8/2'.","MessageDetail":"No action was found on the controller 'EmployeeProjects' that matches the request."}