[英]Broken Routing/Action in Web API
I have my default route defined in WebApiConfig.cs: 我在WebApiConfig.cs中定义了我的默认路由:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional, page = 20, offset = 0 }
);
and in my controller, I have an action: 在我的控制器中,我有一个动作:
// GET api/users
[HttpGet]
public IEnumerable<User> Get(string id, int page, int offset)
{
return id != null
? new User[]{Get(id)}
: _userService.All().Skip(offset*page).Take(page);
}
I know this was recently working, but now I'm getting the infamous "No action was found on the controller 'Users' that matches the request" error. 我知道这最近工作,但现在我得到了臭名昭着的“没有找到控制'用户'匹配请求的行动”错误。 I can't seem to figure what (if anything) changed. 我似乎无法想象什么(如果有的话)改变了。 I've undone all my changes since adding the defaults for page/offset and still nothing. 自从添加页面/偏移的默认值以来,我已经撤消了所有更改,但仍然没有。
any ideas? 有任何想法吗?
request url: http://localhost/api/api/Users
请求网址: http://localhost/api/api/Users
Here parameter 'id' is optional, but the action selector expects to specify a default value for it on the action. 这里参数'id'是可选的,但是动作选择器期望在动作上为它指定默认值。
public IEnumerable Get(string id = null , int page, int offset) public IEnumerable Get(string id = null ,int page,int offset)
Also regarding the url, probably a typo, you mean http://localhost/api/Users
and not http://localhost/**api/api**/Users
另外关于url,可能是拼写错误,你的意思是http://localhost/api/Users
而不是http://localhost/**api/api**/Users
You haven't specified an Action in your route. 您尚未在路线中指定行动。 You either need to add an {action}
piece to your URL, or specify the action in your default
object. 您需要在URL中添加{action}
部分,或在default
对象中指定操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.