我已经像这样配置了我的 WebApiConfig:
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
我有一种接受一个参数的方法。访问 URI 是http://localhost:8598/api/WebApi/GetLocationCategory/87
.
这给了我一个错误:No HTTP resource was found that matches the request URI 'http://localhost:8598/api/WebApi/GetLocationCategory/87'
控制器:
public IEnumerable<LocationCategory_CLS> GetLocationCategory(int CatID)
{
var LocCats = (from lct in entities.tdp_LocationCategories join lc in entities.tdp_LocationMaster on lct.FK_LocationID equals lc.LocationID where lct.IsApproved == 0 && lct.FK_CategoryID == CatID select new { lc.LocationID, lc.LocationName }).ToList();
List<LocationCategory_CLS> loc = new List<LocationCategory_CLS>();
foreach (var element in LocCats)
{
loc.Add(new LocationCategory_CLS
{
LocationID = element.LocationID,
LocationName = element.LocationName
});
}
return loc;
}