使用asp.net mvc

时间:2016-02-11 13:12:00

标签: asp.net asp.net-mvc routeattribute

我使用带有路由属性的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);
        }
    }

为什么我的路由与localhost:5555 / api / test没有找到POST?

这是我的默认路线设置:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapMvcAttributeRoutes();
        }

1 个答案:

答案 0 :(得分:0)

RouteAttribute应该具有前导~