Tôi đã cấu hình WebApiConfig của tôi như thế này:Không tài nguyên HTTP đã được tìm thấy phù hợp với yêu cầu URI trong Web API
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
Tôi có một phương pháp mà chấp nhận một tham số. URI truy cập là http://localhost:8598/api/WebApi/GetLocationCategory/87
.
này mang lại cho tôi một lỗi: No HTTP resource was found that matches the request URI 'http://localhost:8598/api/WebApi/GetLocationCategory/87'
Bộ điều khiển:
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;
}
Giải quyết được vấn đề URI nên là: http: // localhost: 8598/api/WebAPI/GetLocationCategory CatID = 87 – DharaPPatel