我将 asp.net mvc 与路由归因一起使用,但出现此错误:
System.Web.HttpException (0x80004005): No matching action was found on controller 'Test.RequestController'. This can happen when a controller uses RouteAttribute for routing, but no action on that controller matches the request.
public class TestController : Controller
{
[Route("~/api/test")]
[HttpPost]
public async Task<ActionResult> Post(TestRequest r)
{
return new HttpStatusCodeResult(HttpStatusCode.Created);
}
}
为什么找不到我的本地主机:5555/api/test with POST 的路由?
这是我的默认路由设置:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
}
RouteAttribute
不应该有前导~
。