mvc 5 web api routing

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

        routes.MapMvcAttributeRoutes(); 
    }
}
//using


    public class ValuesController : ApiController
    {
        // GET api/values
        public IEnumerable Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        [Route("customers/orders")]
        [HttpGet]
        public string FindOrdersByCustomer() 
        {
            return "Supervalue";
        }

        // POST api/values
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
        }
    }


http://www.codeproject.com/Articles/774807/Attribute-Routing-in-ASP-NET-MVC-WebAPI
http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2

No comments:

Post a Comment

Note: only a member of this blog may post a comment.