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?

1
  • 1
    It seems partly a duplicate, there was an error using the wrong class, as pointed out by @cuong Commented Jul 31, 2012 at 7:59

1 Answer 1

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}
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it was that simple ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.