Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将多个DateTime参数传递给ApicController方法?_C#_Asp.net Mvc 4_Asp.net Web Api_Asp.net Mvc Routing - Fatal编程技术网

C# 如何将多个DateTime参数传递给ApicController方法?

C# 如何将多个DateTime参数传递给ApicController方法?,c#,asp.net-mvc-4,asp.net-web-api,asp.net-mvc-routing,C#,Asp.net Mvc 4,Asp.net Web Api,Asp.net Mvc Routing,(我正在使用WebApi 4.0.20710.0和framework 4.0。我不确定这是否重要,但我们还没有被允许将服务器升级到4.5) 我想做的是打这样的电话: http://domain/api/Books/Outstanding/2013-01-01/2014-01-01 /// <summary> /// Get a list of books that were outstanding between the start and end dates. /// </

(我正在使用WebApi 4.0.20710.0和framework 4.0。我不确定这是否重要,但我们还没有被允许将服务器升级到4.5)

我想做的是打这样的电话:

http://domain/api/Books/Outstanding/2013-01-01/2014-01-01
/// <summary>
/// Get a list of books that were outstanding between the start and end dates.
/// </summary>
public IEnumerable<BookDto> GetOutstanding(DateTime start, DateTime end)
{
    return _repository.GetOutstanding(start, end);
}
routes.MapRoute(
    name: "ActionWithStartAndEnd",
    url: "{controller}/{action}/{start}/{end}"
);
在我的
ApiController
中,我有一个类似这样的方法:

http://domain/api/Books/Outstanding/2013-01-01/2014-01-01
/// <summary>
/// Get a list of books that were outstanding between the start and end dates.
/// </summary>
public IEnumerable<BookDto> GetOutstanding(DateTime start, DateTime end)
{
    return _repository.GetOutstanding(start, end);
}
routes.MapRoute(
    name: "ActionWithStartAndEnd",
    url: "{controller}/{action}/{start}/{end}"
);
然而,这一切实际上都不起作用。最后,我看到一条错误消息,上面简单地说,
“在控制器‘Books’上找不到与请求匹配的操作。”

我怀疑我做了一些简单的错误的事情,和/或误解了一些关于路由的一般性的事情。我该怎么做?我是个白痴

路由不属于RouteConfig,它属于WebApiConfig,它应采用以下形式:

config.Routes.MapHttpRoute(
    name: "ActionWithStartAndEnd",
    routeTemplate: "api/{controller}/{action}/{start}/{end}"
);

但是你的动作名称是
getsumment
而不是
summent
我不得不将代码匿名,可能很糟糕。坦率地说,违约是一种误导。我会移除它们。感谢你回来并给出一个清晰的答案!别忘了你可以接受自己的答案。谢谢!如果允许的话,我会在几天内接受答案(除非其他人设法插嘴提出更雄辩的批评;)