I got an error - No action was found on the controller 'Action' that matches the request.
我得到一个错误——在与请求匹配的控制器“操作”上没有发现任何操作。
The url is http://localhost:37331/api/action/FindByModule/1
.
url是http://localhost:37331 / api /行动/ FindByModule / 1。
The routing I used is
我使用的路由是。
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Controller:
控制器:
public class ActionController : ApiController
{
private IActionRepository repository = null;
[HttpGet]
[ActionName("All")]
public IEnumerable<JsonAction> All()
{
return from action in this.repository.Get()
select new JsonAction
{
ID = action.ID,
Text = action.Text.Trim(),
Description = action.Description.Trim(),
};
}
[HttpGet]
[ActionName("FindByModule")]
public IEnumerable<JsonAction> FindByModule(Int64 moduleId)
{
return from action in this.repository.FindByModule(moduleId)
select new JsonAction
{
ID = action.ID,
Text = action.Text.Trim(),
Description = action.Description.Trim(),
};
}
}
1 个解决方案
#1
87
This is because there is a parameter name mismatch. From your route the value 1 is assigned to parameter named id
and your action is looking for parameter named moduleId
.
这是因为参数名不匹配。从您的路径中,值1被分配给名为id的参数,您的操作正在寻找名为moduleId的参数。
First option is to change your route like this:
第一种选择是像这样改变你的路线:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{moduleId}",
defaults: new { moduleId = RouteParameter.Optional }
);
Second is to change your URL like this:
第二,像这样修改你的URL:
http://localhost:37331/api/action/FindByModule?moduleId=1
So the parameter name match.
参数名匹配。
#1
87
This is because there is a parameter name mismatch. From your route the value 1 is assigned to parameter named id
and your action is looking for parameter named moduleId
.
这是因为参数名不匹配。从您的路径中,值1被分配给名为id的参数,您的操作正在寻找名为moduleId的参数。
First option is to change your route like this:
第一种选择是像这样改变你的路线:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{moduleId}",
defaults: new { moduleId = RouteParameter.Optional }
);
Second is to change your URL like this:
第二,像这样修改你的URL:
http://localhost:37331/api/action/FindByModule?moduleId=1
So the parameter name match.
参数名匹配。