0

Possible Duplicate:
Routing with Multiple Parameters using ASP.NET MVC

Experimenting with the MVC4 web api, I defined the following route, in Global.asax

routes.MapRoute(
  name:="API Default", 
  url:="api/{systemid}/{controller}/{id}",
  defaults:=New With {.id = RouteParameter.Optional}
)

I changed the controller accordingly

Public Class ValuesController
    Inherits ApiController

 Public Function GetValues(systemid As Integer) As IEnumerable(Of String)
     ---
 End Function

 Public Function GetValue(systemid As Integer, ByVal id As Integer) As String
     ---
 End Function
End Class

I was looking to format requests uri like

http://localhost/api/13/values/5 

but the only working call is with explicit parameters, as to

http://localhost/api/values?id=5&systemid=4

Is there a way to accomplish what I was looking for?

Community
  • 1
  • 1
DavideB
  • 609
  • 5
  • 10
  • 1
    It seems partly a duplicate, there was an error using the wrong class, as pointed out by @cuong – DavideB Jul 31 '12 at 07:59

1 Answers1

2

I guess you use the wrong routing class, instead of using Web API routing, you used MVC routing, it should be:

routes.MapHttpRoute(
  name:="API Default", 
  routeTemplate:="api/{systemid}/{controller}/{id}",
  defaults:=New With {.id = RouteParameter.Optional}
)
cuongle
  • 74,024
  • 28
  • 151
  • 206