找不到与请求URI匹配的HTTP资源:(

时间:2015-06-09 22:18:38

标签: asp.net-mvc asp.net-mvc-4 razor

这是我的webApiConfig

public static void Register(HttpConfiguration config)
{
    config.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional });

    config.Routes.MapHttpRoute(
        name: "ApiByActionWithid",
        routeTemplate: "api/{controller}/{action}/{id}",
        defaults: new { action = "" },
        constraints: new { id = @"^[0-9]+$" });

    config.Routes.MapHttpRoute(
        name: "ApiByAction",
        routeTemplate: "api/{controller}/{action}",
        defaults: new { action = "" });

changeOrderState操作如下所示:

public ResponseDTO ChangeOrderState(Int32 changeOrderState, string state) 
{ 
    IRestaurantManager rm = Core.CoreManager.Instance.GetService<IRestaurantManager>(); 
    return rm.ChangeOrderState(changeOrderState, state); 
}

我称之为这样的方法:

https://localhost:44302/api/Restaurant?changeOrderState=1&state=Rechazado

但是它不起作用,但在其他人的调用中,以相同的方式工作

1 个答案:

答案 0 :(得分:0)

我解决了这个问题,答案是添加te方法[HttpGet]中的下一个,我的动作如下:

[HttpGet]
    public ResponseDTO ChangeOrderState(int changeOrderState, string state="")
    {
        IRestaurantManager rm = Core.CoreManager.Instance.GetService<IRestaurantManager>();
        return rm.ChangeOrderState(changeOrderState, state);
    }